how to disable "create" button

how to disable "create" button

sagimannsagimann Posts: 18Questions: 9Answers: 0

Hi all,
I have a simple editor setup, when I click "add", I get a dialog box with some fields. I want to ensure that the "create" button is kept disabled until all fields comply with some "extreme" validation rules, I won't go into it, but the bottom line is that I want the "create" button to remain disabled while the validations are failing, and enabled otherwise.

I was able to add "disabled" attribute to the "create" button, which works great, however, it does not prevent the user from hitting ENTER and passing the dialog anyway... so I guess adding the "disabled" attribute is not enough. How do I also prevent a user from hitting ENTER?

tnx

Answers

  • sagimannsagimann Posts: 18Questions: 9Answers: 0

    i was able to find some sort of solution, not sure if it's the correct way - I intercept onPreSubmit and return false. This effectively prevents the dialog from being dismissed (and the form being submitted). There is, however, some issue with that: any messages I add on fields using message(), error(), etc are removed when I click ENTER. I need to re-validate the form from within the onPreSubmit event before returning false so the messages are redisplayed...

  • allanallan Posts: 63,529Questions: 1Answers: 10,473 Site admin

    Yes, the preSubmit event is the way I would suggest doing this. Another option is to provide your own function for the button activation function and have it perform whatever client-side validation you need before having it then call submit().

    any messages I add on fields using message(), error(), etc are removed when I click ENTER. I need to re-validate the form from within the onPreSubmit event before returning false so the messages are redisplayed...

    That is correct. Isn't your validation function just going to rerun each time anyway though? The reason the errors are cleared automatically is that the fields might have become valid, Editor doesn't know.

    Regards,
    Allan

This discussion has been closed.