Edit Form - additional Save button

Questions related to customising nuBuilder Forte with Javascript or PHP.

Edit Form - additional Save button

Postby Janusz » Thu Jan 17, 2019 9:50 pm

Hi,
I wanted to add additional "Save" button on the edit form and to make it show/hide depanding on the case.

So in case of new record the following code is making button visible - and works OK

Code: Select all
if(nuIsNewRecord()){
$('#button_save').show();
}


To make the button not visible after "save" the following code is working OK
Code: Select all
if (nuFormType() == 'edit') {
  if (nuHasBeenSaved() === 1) { $('#button_save').hide(); }
   }


But I am not able to properly show the button when someone stars to edit already opened form.
I was trying for example code like belowe or some other trials but with no success.
(for example the code belowe is always activating the button)

if(nuIsSaved()){
$('#button_save').show();
}

Can you please let me know how I could implement it?


Janusz
Last edited by Janusz on Fri Jan 18, 2019 4:19 am, edited 1 time in total.
Janusz
 
Posts: 253
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Form edit identification

Postby kev1n » Thu Jan 17, 2019 10:47 pm

Is the button visible by default? If yes, isn't it sufficient to hide the button if you just saved the form?

Code: Select all
if (nuFormType() == 'edit') {

  if (nuHasBeenSaved() === 1) {
      nuHide('button_save');
  }

}
kev1n
 
Posts: 349
Joined: Mon Oct 15, 2018 2:13 am

Re: Form edit identification

Postby Janusz » Thu Jan 17, 2019 11:07 pm

By default I keep this button hidden and want to make it visible when someone will start to edit the record.
In other words - to make this button visible when the standard save button is becoming red. I was trying to use as well nuHasBeenEdited but did not get expected behavior.
Janusz
 
Posts: 253
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Form edit identification

Postby kev1n » Fri Jan 18, 2019 12:23 am

Try this: shows the button if it's a new record or not just saved.

Code: Select all
if (nuFormType() == 'edit') {

  if (nuIsNewRecord() || nuHasBeenSaved() == 0) {
      nuShow('button_save');
  }

}
kev1n
 
Posts: 349
Joined: Mon Oct 15, 2018 2:13 am

Re: Edit Form - additional Save button

Postby Janusz » Fri Jan 18, 2019 4:18 am

Thanks for your support, and suggestion.
I did finally following as I had some issues with the code placed just in main form only.
If someone else would like to implement addional big SAVE button (as I was requested to implement by my wife who is using that databse :) )
here is the full description:

Definition of additional SAVE button, which normaly is hidden and is showing up if someone is starting new record or to modify existing record.

Create button (ID: button_save)
All/type: Input; Input tab: Button; Custom Code tab: onclick nuSaveAction()

In Form properties / Custome code / javascript / place following code :
Code: Select all
$('#button_save').hide();
$('#button_save').css("background", "red");

if(nuIsNewRecord()){
$('#button_save').show();
}

Next in every object on the edit form (edit fields, check boxex, etc)
in custom code, javascript I placed:
Code: Select all
onclick       nuShow('button_save');

(potentally can be used onchange but in such case button appears once you exit the modified field, so im my case I preffered to choose option onclick so the button is shown up once you click inside the field)
Janusz
 
Posts: 253
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Edit Form - additional Save button

Postby kev1n » Fri Jan 18, 2019 5:38 am

Janusz wrote:Next in every object on the edit form (edit fields, check boxex, etc)
in custom code, javascript I placed:
Code: Select all
onclick       nuShow('button_save');



Easier like this:

Code: Select all
if (nuFormType() == 'edit') {
    var inputs = $("#nuRECORD").find(":input:not([type=button])");
    inputs.click(function() {
        nuShow('button_save');
    });
}
}
kev1n
 
Posts: 349
Joined: Mon Oct 15, 2018 2:13 am

Re: Edit Form - additional Save button

Postby Janusz » Fri Jan 18, 2019 6:38 am

Yeah, thanks a lot - your code is working pefectly and much, much faster than changing each object one after another.
(just one bracket to remove at the end of the code)
Janusz
 
Posts: 253
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Edit Form - additional Save button

Postby Janusz » Fri Jan 18, 2019 4:42 pm

I noticed that select field behaves not well if the function click is used and its better for that to use change.
And therefore one more question, how to exclude in the search both button and select.
Code: Select all
...
var inputs = $("#nuRECORD").find(":input:not([type=button])");
...


because afterwards I want to add following: (but it does not work if click is assigned, puttung click to empty - is not helping as well)
Code: Select all
if (nuFormType() == 'edit') {
    var inputs = $("#nuRECORD").find(":select");
    inputs.change(function() { nuShow('button_save');});
    }
Janusz
 
Posts: 253
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: Edit Form - additional Save button

Postby kev1n » Fri Jan 18, 2019 5:34 pm

var inputs = $("#nuRECORD").find(":input:not([type=button])").not('select');
kev1n
 
Posts: 349
Joined: Mon Oct 15, 2018 2:13 am

Re: Edit Form - additional Save button

Postby Janusz » Fri Jan 18, 2019 6:47 pm

Thanks, working fine.
Janusz
 
Posts: 253
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Next

Return to Custom Code