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
Improved form requests #505
Conversation
7f2bc53
to
e1a3e2b
Compare
What about validating inputs when they lose focus? |
Could do that but it will fire a lot of AJAX requests in the background |
example: element 'brand' has rule 'array' if it fails, the element may be called 'brand[]' so we need to append '[]' to find the correct element
It shouldn't? In theory there should only be a request when the user switches from one input to the next, which doesn't happen very often. However, looking at this again, it would seem like the last input would only be validated when clicking the submit, since most users don't change the focus of the last input and instead go straight to the submit button. |
The validation is registered against a hidden field that's generated dynamically on page load. Validation will only occur on form submission, as there are no "real" ( |
I'm missing something. Maybe I got the wrong version? This has now just caused the entire thing to stop working. It now refreshes the page and ignores the entire check and falls back on Server side. Also, the form now has a novalidate element. ---- Nevermind --- I'm abandoning using this project. It just doesn't work very well, and I'm now stuck with new problems and very little motive to continue down this path. Thanks for the work, I'll try using it on another project at another time. |
Usage
Change your form request to
extends \Proengsoft\JsValidation\Remote\FormRequest
. Then use\JsValidator::formRequest(MyRequest::class)
Description
This solves several issues with client side validation of form requests:
$this->some_input_data
- this data will only be available in a real request.How does it work
A single AJAX request validation rule is registered against a dummy
input[type=hidden]
field which is generated on-the-fly.When you submit the form an AJAX fires which does the form request validation. The error response is then mapped back to the input fields in the DOM and errors displayed using
jquery-validation
methods.Potential pitfalls
Previously inputs were validated as you typed. Now they're only validated when you submit the form. If you change an invalid input, it's no longer immediately validated so the error will go away. When you submit the form, if it's still invalid the error will be reshown.