-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ajax validation rule. #261
Comments
The perfect solution I think would allow to invalidate input like this: Formsy.addValidationRule 'isUnique', (inputRef, values, value)->
return checkUnique(inputRef, values, value)
checkUnique = _.debounce((inputRef, values, value)=>
unique = false
request = $.ajax url: '/uniqueness-check', method: 'POST', data: {field: 'PaymentGateway.name', value: value}, dataType: 'json'
request.done (response)->
if response.status
unique = true
unless unique
inputRef.invalidate()
, 300) |
+1 It would be great to arbitrarily declare an input as invalid. |
For anyone who need to validate some field with an AJAX request here are an work around example:
|
@jcrjaci When I try using your solution, I get the following error: Lines 311 to 313 in f7cf41d
If you pass a function as validator it throws an error. Is there another way of doing this? |
I want to add validation rule to check if value is unique in database. So basically I just post request to back-end and wait till i get response if value is unique or not. Also I use underscore.js's debounce function to reduce calls to server. But input is being invalidated before ajax callback comes.
Code looks something like this:
I tried many different version, but nothing seems to work. I also tried to validate input in Input component. I just accessed validations props and checked if it had isUnique parameter and validated it -
errors = uniqueCheckErrors || this.getErrorMessage()
., but I could figured out how to add error to Formsy error stack(so I could get them throughthis.getErrorMessage()
) so form would act as normal.The text was updated successfully, but these errors were encountered: