Skip to content
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

yiiActiveForm('validate', true) submits form #16109

Closed
adhayward opened this issue Apr 17, 2018 · 2 comments
Closed

yiiActiveForm('validate', true) submits form #16109

adhayward opened this issue Apr 17, 2018 · 2 comments
Labels
JS JavaScript related

Comments

@adhayward
Copy link
Contributor

I'm trying to force validate on a form before displaying a confirmation to the user.

So I've tried calling:
$('#formId').yiiActiveForm('validate')
Which didn't appear to do much.

Then I tried to use the forceValidate option:
$('#formId').yiiActiveForm('validate', true)

This validated everything as expected but immediately triggered the form submit which I don't want yet.

Looking at the code in yii.activeForm.js the validate function starts with:
if (forceValidate) { $(this).data('yiiActiveForm').submitting = true; } ...

  • Is there a way to trigger validation of all fields in the form (and show error messages to the user) without submitting it?

  • Is it worth renaming the forceValidate parameter here to something like submitWhenValid so it's more obvious what it does or creating a second parameter so that we force all fields to be validated without submitting the form?

Q A
Yii version 2.0.13
PHP version 7.0
Operating system Windows 10
@alex-code
Copy link
Contributor

Possible dup #13105

@samdark samdark added the JS JavaScript related label Apr 17, 2018
@samdark samdark added this to the 2.0.16 milestone Apr 17, 2018
@SilverFire
Copy link
Member

Closing as a duplicate

@rob006 rob006 removed this from the 2.0.16 milestone Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
JS JavaScript related
Projects
None yet
Development

No branches or pull requests

5 participants