Page 1 of 1

Custom button on edit form when editing existing record only

Posted: Sat Apr 03, 2021 4:19 pm
by absalom
Hi, newbie here.

I have an "edit" form which for adding new records as well as editing existing records. Furthermore, once "Save" has been clicked, the new record now is an "existing record".

I would like to add a button redirecting to a separate "edit form" for creating a new record in a second table, but since the primary key of the currently edited record will be a foreign key in the second form (reached by clicking the button), I would like the button to be unclickable (or even hidden) as long as the current record hasn't be saved into the database.

A still better requirement would also to show some warning message if the user has modified some fields in the current record, and then tries to click the button for being redirected to the second form without having previously saved his/her modifications.

Also, how can I build my second form for managing the foreign key? I would like to have this (possibly hidden) field to be automatically set to the primary key of the initial record.

How can I do such a thing?

Re: Custom button on edit form when editing existing record

Posted: Sat Apr 03, 2021 4:50 pm
by kev1n
Hi and welcome to nuBuilder!

To hide your button when the form is loaded, add this JavaScript to your form's Custom Code.

Replace 'your_button_id with the ID of your button. Use nuEnable() instead of nuShow() to enable/disable it instead of showing/hinding.

Code: Select all

if (nuFormType() == 'edit') {
   nuShow('your_button_id', ! nuIsNewRecord());
}
Are you openening the second form in a Popup window or new tab?