I have got the form and I do some things after validate with ajax on the page. I do it with .on('afterValidate', function ()
And all works good, but only first time. After it form is not working, if I will work with it second time. How I can refresh frontend validation and work with this form again and again on submit? Just .on('submit'
- is not good idea, because form works twice in this mode (form submitted two times, because validation from backend will be).
Asked
Active
Viewed 749 times
0
![](../../users/profiles/1131137.webp)
Сергей Илларионов
- 369
- 1
- 4
- 14
1 Answers
0
I think for AJAX-based validation you should use another event:
ajaxComplete event is triggered after completing an AJAX request for AJAX-based validation. The signature of the event handler should be:
function (event, jqXHR, textStatus)
where
event
: an Event objectjqXHR
: a jqXHR objectsettings
: the status of the request ("success", "notmodified", "error", "timeout", "abort", or "parsererror").
Can't find it in official docs, you can see it here in var = events { ... }
So try .on('ajaxComplete', function (event, jqXHR, textStatus) { ... })
instead of .on('afterValidate', function ({ ... })
.
![](../../users/profiles/4323648.webp)
arogachev
- 31,868
- 6
- 105
- 113
-
Thank you for your answer. My form works without ajax yii settings. I just create form.preventDefault() and after it do some code and send ajax to backend. My customer wants to see "on fly" profile edit – Сергей Илларионов Mar 20 '15 at 06:59
-
can you also take look on this question? http://stackoverflow.com/questions/29154544/how-to-solve-bad-request-400-unable-to-verify-your-data-submission-in-yii2 – Сергей Илларионов Mar 20 '15 at 06:59
-
How to switch on yii ajax validation? – Сергей Илларионов Mar 20 '15 at 14:06
-
What do you mean by that? Validating when switching between fields? – arogachev Mar 20 '15 at 15:39