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

Use validation outside the context of a form #43

Open
btantlinger opened this issue Dec 21, 2012 · 5 comments
Open

Use validation outside the context of a form #43

btantlinger opened this issue Dec 21, 2012 · 5 comments
Milestone

Comments

@btantlinger
Copy link

jqBootstrapValidation seems to only work inside the context of a form submit. But this does not work well with some use cases. Why can't I validate a single component any time I want? something like:

$('#my-text-field').jqBootstrapValidation('validate');

To have the validation error show for that component?

@ReactiveRaven
Copy link
Owner

Because it was only supposed to be for forms ;)

Unfortunately, you do need to 'set up' the field first (if you've copy-pasted step 2 from the installation in the docs, your fields should already be set up), but you can do something similar to what you've asked:

var $inputs = $("#my-text-field");
$inputs.jqBootstrapValidation(); // set up; ideally only called on each field once

// triggers the field(s) to show the error-state if something is wrong
$inputs.trigger("change.validation", {submitting: true});

If you want to do something with the error messages but not display them in help-blocks, you can also get them with collectErrors:

var errors = $("...").jqBootstrapValidation("collectErrors");

// {
//   "username": ["...", "..."],
//   "password": ["...", "..."]
// }

I'll mark this as an enhancement request too, it would make sense for it to be easier.

@btantlinger
Copy link
Author

Awesome, thanks!

@kenyee
Copy link

kenyee commented May 3, 2013

I'd like to second the enhancement request. E.g., I'm trying to use this w/ Meteor.js and forms aren't really "submitted". You catch the click event on the submit button, then do an ajax call to call a web method, then do a return false to prevent the click from doing the actual submit.
Would be nice if there were some way of saying "validate this form and display errors in help block now". There can also be multiple forms on the page at once, but they're hidden because it's a single page app framework (no browser refresh/reload at all).

@tuxicon
Copy link

tuxicon commented May 14, 2014

Yes, this enhancement would be great to have!

@skybondsor
Copy link

+1 for adding this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants