Welcome to the nuBuilder Forums!

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

Buton Save - Show or Hidden

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
cjuliao
Posts: 12
Joined: Fri Mar 23, 2012 2:58 am
Has thanked: 1 time
Been thanked: 1 time

Buton Save - Show or Hidden

Unread post by cjuliao »

Good evening. How do I make it so that when editing a form, the 'save' button is shown or hidden based on a field called 'approved' (Yes/No)? If it is 'Yes', hide the save button; if it is 'No', then show the save button. The above is to protect the data. I appreciate your help.
kev1n
nuBuilder Team
Posts: 4291
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 444 times
Contact:

Re: Buton Save - Show or Hidden

Unread post by kev1n »

Hi,

In the form's Custom Code, add this JavaScript:

Code: Select all

// Function to toggle the visibility of the Save button based on 'approved' checkbox state
function toggleSaveButton() {
  var isApproved = nuGetValue('approved'); // Retrieves true if checked, false otherwise

  // If 'approved' is checked (true), hide the Save button; otherwise, show it
  nuShow('nuSaveButton', isApproved); // Second parameter 'true' hides the element
}

// Execute the function when the form loads
toggleSaveButton();

// Also execute the function when the 'approved' checkbox state changes
$('#approved').change(function() {
  toggleSaveButton();
});
:arrow: If the "approved" field's ID differs from 'approved', adjust the code accordingly to match the actual ID.
Post Reply