I am currently coding a form where I would like the buttons to disable after submission of the form.
This is a snippet of what I have so far regarding that (because I have over 20 fields so I’ll just show the one) and I still need to limit the form submissions to one per user, but after submission the input elements still aren’t disabling and I’m not entirely sure where I’m going wrong…
export function submit_click(event) {
if ( $w( ‘#iptName’ ).enabled ){
$w( ‘#iptName’ ).disable();
then( () => {
console.log( “Element now disabled” );
} );
}
Hi Erin,
Just a little syntax adjustment, and you’ll have it working.
export function submit_click(event) {
if( $w('#iptName').enabled ){
$w('#iptName').disable()
.then( () => {
console.log("Element now disabled");
});
}
}
There are shortcuts to applying a certain setting to multiple elements of the same type. This disables all of the buttons on the page.
export function DisableButtons(){
let buttonElements = $w("Button");
buttonElements.disable();
}
Or if there are some buttons that you don’t want to disable, you can group the buttons that you do want to disable together in one command:
$w("#button1,#button2,#button3").disable();
Thanks so much. Would this work for input fields as well? What I am trying to accomplish is that once the form has been submitted all the input fields become disabled too.
@eringray1988 It would.
let inputElements = $w("TextInput");
@tony-brunsman this is my final code for that function
export function submit_click(event, $w) {
disableTextInput()
}
function disableTextInput() {
let inputElements = $w( “TextInput” );
if ( $w(inputElements).enabled ){
$w(inputElements).disable()
.then( () => {
console.log( “Element now disabled” );
});
}
}
but this is what I’m getting returned from the console log:
Error: The value passed to the element selector function (usually $w), must be of type string
Do I have to define each input element like $w(“#inputName, #inputNumber”) because I have about 25 input fields.
@eringray1988 inputElements is an array that you will have to loop through if you want to evaluate each one’s enabled property:
function disableTextInput() {
let inputElements = $w("TextInput");
inputElements.forEach((inputElement) => {
if(inputElement.enabled ){
inputElement.disable()
.then( () => {
console.log("Element now disabled");
});
}
})
}