Disabling Button

I’m trying to disable a button based off of previous form submissions, for some reason the button remains enabled.

$w.onReady( function  () { 
    user.getEmail() 
        .then((email) => { 
 let  userEmail = email // "user@something.com"    
wixData.query("Events") 
                .eq('usernameEmail', userEmail) 
                .count() 
                .then((num) => { 
 let  nos = num; 
                    $w("#submittedsofar").value = num; 
                    $w("#eventsdatasetsubmission").setFieldValue('eventNumber', $w("#nos").value); 
                    $w("#remainingnos").valu`Preformatted text`e = ($w("#initialnumber").value) - ($w("#submittedsofar").value); 
                    $w("#eventsdatasetsubmission").setFieldValue('remainingSubmissions', $w("#remainingnos").value); 
 
if  ($w("#remainingnos").value > 0) { 
                        $w("#buttonStart").enable; 
                        $w("#startmessage").show; 
                    }  

else { 
                        $w("#buttonStart").disable; 
                        $w("#startmessage").hide; 
                    } 
                }) 
        }) 
})

The value in an input field is a string and not a number .

This:
if ($w(" #remainingnos ").value > 0) {

should be something like this:
if (Number($w(" #remainingnos ").value) > 0) {

It still isn’t working for some reason.

Why are you still posting multiple posts about the same question :dizzy_face:

https://www.wix.com/corvid/forum/community-discussion/enabling-disabling-button-using-if-then-login

try this

$w(“#buttonStart”).disable();

1 Like

I was going through the forum and came across this and noticed you had some incorrect syntax like emanu2000 mentioned - in that you were missing the () on enable, show, disable and hide.

You don’t use parenthesis if you’re referring to states like enabled, which is checking the enabled property status of in this case a button, but you do in a function like enable(), which turns the property to true and enables the button so users can interact with it.

I didn’t test the code outright since I was unsure of the setup of the collections but it should look more like this:

$w.onReady(function () {
    user.getEmail()
        .then((email) => {
            let userEmail = email; // e.g., "user@something.com"
            wixData.query("Events")
                .eq("usernameEmail", userEmail)
                .count()
                .then((num) => {
                    // Update the value of #submittedsofar
                    $w("#submittedsofar").value = num;

                    // Calculate remaining submissions
                    let initialNumber = $w("#initialnumber").value; // Ensure this element exists and has a value
                    let remainingSubmissions = initialNumber - num;

                    // Update the dataset fields
                    $w("#eventsdatasetsubmission").setFieldValue("eventNumber", num);
                    $w("#eventsdatasetsubmission").setFieldValue("remainingSubmissions", remainingSubmissions);

                    // Update the value of #remainingnos
                    $w("#remainingnos").value = remainingSubmissions;

                    // Enable or disable the button based on remaining submissions
                    if (remainingSubmissions > 0) {
                        $w("#buttonStart").enable();
                        $w("#startmessage").show();
                    } else {
                        $w("#buttonStart").disable();
                        $w("#startmessage").hide();
                    }
                });
        });
});