Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Edit Form - additional Save button

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Edit Form - additional Save button

Unread post by Janusz »

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 Thu Jan 17, 2019 7:49 pm, edited 1 time in total.
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Form edit identification

Unread post by kev1n »

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');
  }

}
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Form edit identification

Unread post by Janusz »

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.
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Form edit identification

Unread post by kev1n »

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');
  } 

}
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Edit Form - additional Save button

Unread post by Janusz »

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)
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Edit Form - additional Save button

Unread post by kev1n »

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');
    });
}
}
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Edit Form - additional Save button

Unread post by Janusz »

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)
If you like nuBuilder, please leave a review on SourceForge
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Edit Form - additional Save button

Unread post by Janusz »

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');});
    }
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: Edit Form - additional Save button

Unread post by kev1n »

var inputs = $("#nuRECORD").find(":input:not([type=button])").not('select');
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: Edit Form - additional Save button

Unread post by Janusz »

Thanks, working fine.
If you like nuBuilder, please leave a review on SourceForge
Post Reply