question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

custom validator cannot work when using ajax

See original GitHub issue

Hi, I want to use custom validator to validate if the username is in database, however, when I use callback in validate functions, it cannot work, and always return false

<MyInput name='name' title='name' validations={{
    nameExistenceCheck: function (value) {
      if (value.name === undefined || value.name.length < 5) {
        return false;
      } else {
        // ajax
        DataSource.isNameExisted(value.name, function (response) {
          if (response.data.msg === 'available') {
            return true;
          }
        })
      }
    }
    }}  validationError='Length less than 5 or the name is already existed!'/>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
scotrocommented, Sep 18, 2015

The example would work for onSubmit, however onChange doesn’t provide an invalidate in the args it passes to the handler.

It is possible to set validation errors on the form component as an alternative to calling invalidate. Unfortunately, doing so appears to override the built-in validation at the component level.

0reactions
christianalfonicommented, Oct 2, 2015

Let me know if is needed to discuss this more!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom Validation not working with Ajax MVC Call
The problem is that the submit action is executing without waiting for the response of the custom validation which return false. Any idea...
Read more >
custom validators not working from inside AJAX update panel
I have a webform containing custom validator inside AJAX update panel and a button control inside another AJAX update panel. When user clicks...
Read more >
CustomValidator Not Working with RadEditor - Telerik
I have this code <asp:CustomValidator id="valreqEditComment" ControlToValidate="reEditComment" ClientValidationFunction="TestWordCount"
Read more >
Custom validation on ajax request - WordPress.org
Hello, I would like to hook on ajax validation of the form and display some custom errors by some extra checks i am...
Read more >
Getting Data from Users: Validating Input - Yii Framework
To enable AJAX validation for a single input field, configure the enableAjaxValidation property of that field to be true and specify a unique...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found