Skip to content
This repository has been archived by the owner on Mar 12, 2020. It is now read-only.

Validator not working with hidden forms #317

Closed
vatsalpande opened this issue Apr 20, 2016 · 5 comments
Closed

Validator not working with hidden forms #317

vatsalpande opened this issue Apr 20, 2016 · 5 comments

Comments

@vatsalpande
Copy link

vatsalpande commented Apr 20, 2016

I have two tabs ( A & B) and two forms (FormA & FormB) and I toggle the visibility of my forms on click of every individual tab. The form(FormA) that is shown in page load works fine but when I click on another tab the submit button is enabled for FormB even when the required values are not filled.

If I remove the hide class and show both the forms at page load the submit button is disabled and works as expected. If I switch the views FormB on page load then Form B works and FormA doesn't work.

I tried to look at the issues but couldn't find similar issue. Please suggest if this is a known issue or this will be taken care of in future releases.

Added jsbin replicating the issue
http://jsbin.com/yijatap/edit?html,console,output

Thanks,
Vatsal Pande

@KevinLobo
Copy link

Known issue I think. Same here.

@filiplh
Copy link

filiplh commented Apr 29, 2016

Similar issue here:

Got a div (with a form inside) that has collapse class.
So initially it's hidden. When I toggle so that it becomes visible,
and I press submit, in the validator().on("submit", the event.isDefaultPrevented() is always false.

Doing the same thing without having collapse class (so div AND form are visible)
and press submit, event.isDefaultPrevented is true as expected.

Any workarounds of fixes are welcome. :)

@vatsalpande
Copy link
Author

vatsalpande commented May 1, 2016

Found the solution, fixed it and Raised a PR for the same.
Hoping to get it approved :)

Fix Here
http://jsbin.com/dewetiv/edit?html,js,output

@1000hz
Copy link
Owner

1000hz commented May 1, 2016

By default, hidden input fields are not validated. With the release of 0.10.0, the input fields that get validated are cached for performance reasons, meaning that when a field becomes visible it still won't get validated. In the next version, the caching will become opt-in.

You can work around your issue by initializing the validator on the tab shown event, or putting $.fn.validator.Constructor.INPUT_SELECTOR = ':input:not([type="submit"], button):enabled' somewhere in your code.

@1000hz 1000hz closed this as completed May 1, 2016
@edgarjaviertec
Copy link

I have tried your solution posted and it worked, thank you 1000hz!

1000hz added a commit that referenced this issue Jul 15, 2016
If you want this behavior back, add
`$.fn.validator.Constructor.INPUT_SELECTOR += ':enabled:visible'`
to your code. (refs #115) (refs #134) (refs #317)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants