Page 1 of 1

Click save but keep form open

Posted: 08 Nov 2017
by Oz.Ab
Hi guys.

I have added a new button to my edit form.
This button is supposed to save the form without closing the form. So the user can fill in the form and save, but still continue with the form open.

If I add:
fd.save().click();

It saves and closes the form.

Can you assist, how can I save and keep the form open?

Regards :)

Re: Click save but keep form open

Posted: 08 Nov 2017
by Nikita Kurguzov
Hello, Oz!
You can just open Edit Form again after saving it. The page will still refresh, but you will stay on the form:

Code: Select all

fd.onsubmit(function() {
  fd.sourceFormParam('fd_Item_EditForm.aspx?ID=' + GetUrlKeyValue('ID'));
  return true;
});
This will override the save button functionality too, though.

But you can have two buttons, for example, Save and Save and Submit.
Save will refresh the page, but Save and Submit will also close the form.

You'll need to add this code to JavaScript editor:

Code: Select all

var saveOnly = false;

$( ".saveOnlyButton" ).click(function() {
  saveOnly = true;
  fd.save().click();
});

fd.onsubmit(function() {
  if (saveOnly)
    fd.sourceFormParam('fd_Item_EditForm.aspx?ID=' + GetUrlKeyValue('ID'));

  return true;
});
And also add button with saveOnlyButton class to the Edit Form, so it looks like this in the end:
SaveOnlyButton.png
SaveOnlyButton.png (54.26 KiB) Viewed 1937 times
P.S. Make sure the form is not opened in dialog mode, otherwise the redirect will not work!
It will only work for a form opened in regular mode.

Re: Click save but keep form open

Posted: 08 Nov 2017
by Oz.Ab
Thanks Nikita - I used the second recommendation with the "saveOnlyButton".

I just needed to change the "fd_Item_EditForm.aspx" to the correct name that is on my form.

There is just one thing that I need to fix in this - hopefully with your assistance.

On the default Save button I have an a alert, the alert is written in the "OnClick" section for the button. This alert is not supposed to pop up when I hit my new button "saveOnlyButton". But as it is now this alert pops up when I click my new button.

How can I stop the alert to pop up when I click my new button?

Regards :)

Re: Click save but keep form open

Posted: 08 Nov 2017
by Nikita Kurguzov
Hmm, you can remove alert from OnClick event and slightly change onsubmit block:

Code: Select all

fd.onsubmit(function() {
  if (saveOnly)
    fd.sourceFormParam('fd_Item_EditForm.aspx?ID=' + GetUrlKeyValue('ID'));
  else
    alert('Saving the form!');

  return true;
});