vojtech-dobes / nette.ajax.js

Flexible AJAX for Nette Framework. Supports snippets, redirects etc.
https://componette.org/vojtech-dobes/nette.ajax.js/
MIT License
149 stars 85 forks source link

Validation problem in Nette 2.4 #128

Closed motorcb closed 7 years ago

motorcb commented 8 years ago

Hello,

i have problem with Nette 2.4 and validation data in input.

I have this example with Nette 2.4: https://github.com/motorcb/nette-ajax-bug

Problem is in validation in component:

$form->addInteger('hours', '')
->setRequired(TRUE)
->addRule(Form::RANGE, 'Zadejte počet hodin (%d až %d)', array(0, 99))<br/>
->setAttribute('class', 'form-control')<br/>
->setAttribute('placeholder', 'Počet hodin');

This rule is never call.

When is remove from form class ajax validation is OK.

Is problem in that a new netteForms.js use onsubmit? https://github.com/nette/forms/commit/97a6638a2cacde72e4fd1f6cf8e98828b47196cd ? And Nette.ajax.js is used onsubmit? https://github.com/vojtech-dobes/nette.ajax.js/blob/master/nette.ajax.js#L323

Thanks

dg commented 8 years ago

I think that line 323 can be simplified with jQuery:

if (analyze.form.get(0).onsubmit && analyze.form.triggerHandler('submit') === false) {
   ...

and this issue can be fixed this way:

if ((analyze.form.get(0).onsubmit ? analyze.form.triggerHandler('submit') : Nette.validateForm(analyze.form.get(0))) === false) {
   ...
vojtech-dobes commented 7 years ago

Form validation compatibility with Nette 2.4 was fixed in 2.2.0.