how to disable validation for ajax form reload

mcmatak
Member | 492
+
0
-

If i change selectbox, or change radiolist, or check checkbox, always it is a new state for form. And form muset be regenerated and as a snippet replaced.

But how to do it if i have validations. I have only one submit button.

Nothing works for me.

I have Nette 2.2.7

$button = $form->addSubmit('save', "adm.buttons.save");
$button->setValidationScope($form['number']);
result: Validation scope accepts only Nette\Forms\Container or Nette\Forms\IControl instances

but even if it would worked, i am afraid that submitting this form caused that javascript validation is triggered and it doesnt allow that the number would not be filled

next try

$form['number']->addConditionOn($form['save'], $form::SUBMITTED)->addRule($form::REQUIRED, 'adm.extensions.modal.numberValidation');

also it doesnt work

what next?

David Matějka
Moderator | 5609
+
0
-

You have to pass an array to the setValidationScope method, see doc

Comments

mcmatak:

doesnt matter, it doesnt work in both cases? I mean yes, it works that there is no error, but the validation is still on.

4 years ago
marlonbrando921
Member | 1
+
0
-

You can prevent the form from submitting with

$(“#prospects_form”).submit(function(e) {
e.preventDefault();
});
Of course, in the function, you can check for empty fields, and if anything doesn't look right, e.preventDefault() will stop the submit.

vignesjoseph
Member | 1
+
0
-

Add this onsubmit=“return false” code:

<form name=“formname” onsubmit=“return false”>
That fixed it for me. It will still run the onClick function you specify
Selenium Training in Chennai