How to set conditions on when to disable a button in UI builder

tidert_24
Kilo Sage

Hello everyone, 

 

Not familiar with the syntax in scripting in UI builder. What I want to do is I want the button to be disabled first if there is no text entered in the HTML field. I know that there is a toggle to disable a button but how can I set it to enabled if the field is not empty?

tidert_24_0-1696566785613.png

 

I appreciate any help. Thank you in advance.

5 REPLIES 5

In UI Builder, you can disable the request approval button based on conditions by using JavaScript code.

SayaliGurav_0-1696827823461.png

Check and compare the conditions mentioned in your code.

Here's an example of how you can do it:
javascript
// Assuming 'submitButton' is the ID of your button and 'inputField' is the ID of your input field

const submitButton = document.getElementById('submitButton');
const inputField = document.getElementById('inputField');

inputField.addEventListener('input', function() {
if (inputField.value.trim() !== '') {
submitButton.disabled = false;
} else {
submitButton.disabled = true;
}
});
In this example, the script listens for changes in the input field. If the input field is not empty (after trimming any whitespace), it enables the submit button. Otherwise, it disables the submit button.

Make sure to replace 'submitButton' and 'inputField' with the actual IDs of your button and input field.

Remember to include this script in the appropriate part of your UI Builder project where it can be executed. Keep in mind that you might need to adjust the code based on the specific details of your project.

 

Thanks & Regards,

Sayali Gurav