jQWidgets Forums

jQuery UI Widgets Forums Plugins Validator, Drag & Drop, Sortable Manually set validator error

This topic contains 10 replies, has 2 voices, and was last updated by  dperry 11 years, 8 months ago.

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
  • Manually set validator error #31129

    dperry
    Participant

    I’ve got a form using the validator, and one field validating using an ajax post and commit(). That works just fine. I’d like to be able to, after validation passes, post the form with ajax, get a response back, and then manually trigger any errors based on the response from the server.

    Example: I’m checking the username for an addUser form with an ajax call to see if the username has been taken. Let’s say that in the time between when the user enters a valid username and then clicks submit, someone else already registers the username. The response object would come back from the server saying the username was taken.

    How could I display the field’s JQValidator message displaying the message from the server after successfully submitting the form? I’d like to be able to check the entire form server-side and display any errors, per-field, that the form validator may have missed.

    Manually set validator error #31149

    Peter Stoev
    Keymaster

    Hi dperry,

    We have a sample which does server validation and shows how that could be achieved with jqxValidator – http://www.jqwidgets.com/jquery-widgets-demo/demos/php/registration_form.htm?arctic

    Hope it helps you.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com/

    Manually set validator error #31183

    dperry
    Participant

    I had used that example for validating a single field, but what I would like to do is submit the form after it has been validated, and then manually trigger any error messages received back from the server (multiple messages, not just using the commit() method within a single field validator).

    The server might say that the username is already taken, a date supplied might not fit within some data range, and perhaps a message saying that some combination of values entered isn’t valid for some reason.

    Thanks

    Manually set validator error #31185

    Peter Stoev
    Keymaster

    Hi dperry,

    The example does exactly that. You can submit the Form only if it is validated. And for example the DateTimeInput used in the sample makes a Server Request to check whether the entered date is valid or not. If the result is invalid date, the Form would not be submitted.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Manually set validator error #31186

    dperry
    Participant

    I understand that, I would like to be able to apply any validation errors after submitting it. After the form has been validated, I would submit the form using an ajax post, and get a response back from the server containing any validation information that could not easily be done client-side. If there are any server-side errors that come back after submitting the ‘validated’ form, I would like to display those errors through the jqxValidator.

    Manually set validator error #31190

    Peter Stoev
    Keymaster

    Hi dperry,

    The “validate” method of jqxValidator will check all fields whether they are valid or not and will display validation errors if the validation fails. I suppose that you can use it in your scenario in combination with the custom validation rules.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Manually set validator error #31191

    dperry
    Participant

    I guess the more direct question is ‘can I manually display an error through the jqxValidator?’ I would like to do client-side validation, and when that passes, perform a server-side validation and display any errors that come back in the ajax response. So the client-side would use the normal jqxValidation rules, and then if the actual form post comes back with any errors from the server, trigger an error message manually, perhaps with an event.

    Manually set validator error #31195

    Peter Stoev
    Keymaster

    Hi dperry,

    The “validate” method will display the validation messages if it is necessary and if you have custom validation rules, you can return true or false so through custom validation rules you can achieve the validation you need.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Manually set validator error #31197

    dperry
    Participant

    I still get all that. Is there a way to display a validation message that originated from outside the jqxValidator rules? Such as from a server-side response after submitting a ‘valid’ form?

    Manually set validator error #31223

    Peter Stoev
    Keymaster

    Hi dperry,

    That is what I meant by custom validation rules. As you know you can write custom validation functions which you can use to perform custom validation as in your scenario i.e you can have some boolean flags in these functions and perform or not validation with them depending on your logic.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com

    Manually set validator error #31253

    dperry
    Participant

    I think I see, you’re saying have some rules for each of the fields that could get validated server side. Those rules would have some kind of boolean flag that would prevent them from being executed under normal circumstances. After posting the form and receiving the error messages associated with the fields, set the appropriate flags and then call $form.jqxValidator(‘validate’), correct?

    That should work for exactly what I need, thank you very much Peter.

Viewing 11 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.