You should be able to call $('#myForm').form('is valid') and have it return a boolean value.
A use case is preventing a modal from closing onApprove by returning if the form is valid.
You could also store the current validation state in your client-side code and update it in the onValid and onInvalid callbacks. You should be storing as little state as possible in your DOM, in my opinion. Not storing the state in the form would mean an "is valid" method would require revalidation.
I initially wanted this too but then realized it's best to keep track of the state yourself. It helps make your code more testable.
I agree with Knotix this should be a behavior. I don't know why I missed it. Will add as a high priority enhancement for 0.x
Is this a additional naming thing? Because in Angular I current check the form by calling:
$scope.isInvalid = function () {
return !registrationForm.form('validate form');
};
It's been a year, any updates on this?
Or is there another way to synchronously know whether a form is valid?
Is there anyway to listen if the form is valid or not - If the form is valid/invalid I would like to toggle the disabled class in the submit button so the user cannot close the modal unless all fields are valid?
Still need solution to check if form is valid from my code...
Lost this thread somewhere in the ages. Will revisit some additional, obvious, missing form behaviors after 2.0 launch.
@DruidKuma
I've added is valid method as a stopgap. Returns true/false if form validates.
i.e.
if ( $('form').form('is valid') ) {
// do something
}
Will be in 2.0
@jlukic
Very impressed with such a quick solution. Thank you very much.
The biggest problem with this project is just keeping on top of open issues. Feel free to +1 any other threads that need attention.
It would be great if there was a way to silently ask a form if it validates _without_ all errors popping up.
Use case: Toggle enabled state on submit on the fly.
Right now a call to form('is valid') gets really messy on an empty form. This is in some cases not desirable.
On a sidenote: It would be great if the validation state was reflected on the form the same way it is relected on individual fields via the error-class.
@erlando +1
So I'm going to set is valid to no longer update UI by default. This was a mistake that got codified, and I'm pretty sure no one is expecting is valid to behave that way.
See #4093 for other changes to these functions in 2.2.8, which will also allow you to validate individual fields by name and see if an individual field is valid.
Added in 2.2.8 as described above.
Most helpful comment
@DruidKuma
I've added
is validmethod as a stopgap. Returnstrue/falseif form validates.i.e.
Will be in
2.0