Get 2024 Templates Mega Bundle!$1000 worth of 19 Bootstrap HTML, Vue & React Templates + 3 Vector Sets for just $99
Get for 99$

Laravel and FormValidator


HI
I'm about to start a project with Metronic 8.2.3 and Laravel 10. As soon as it was installed I ran some tests on the validation of the Users form. In my case the validation is managed by Livewire. I would like it to be handled by the FormValidator library instead. Can you kindly give me a simple example? Thank you


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (4)


Hi

To use FormValidation with Livewire during form submission, you can try these:

Ensure your Livewire component is set up to handle form submission. Use the wire:submit directive to point to the method that will process the form.

In your JavaScript file, initialize FormValidation on the form element. You’ll need to specify the form ID and the validation rules according to the FormValidation documentation.

To integrate FormValidation with Livewire, you can listen for the form’s submit event in JavaScript and manually trigger Livewire’s form submission only if the form passes validation. Here’s a sample JavaScript snippet:

document.addEventListener("livewire:load", function () {
const formValidation = FormValidation.formValidation(
document.getElementById("your-form-id"),
{
// Your validation rules
}
);

document.getElementById("your-form-id").addEventListener("submit", function (e) {
e.preventDefault();

formValidation.validate().then(function(status) {
if (status === "Valid") {
window.livewire.emit("submitForm");
}
});
});
});


In your Livewire component, create a method named submitForm (or whatever you named it in the JavaScript emit function) to handle the form submission after validation.

Optionally, you can also include server-side validation in your Livewire method to ensure data integrity, even if the client-side validation is bypassed.



Hi James Herris

Sorry for the delay in response. When you mention the FormValidator library, are you referring to a specific Laravel package for form validation or the FormValidation JavaScript library? Knowing which library you're referring to will help provide a more accurate example for your form validation setup.



Thanks for reply.
I apologize for the inaccuracy. I am referring to the FormValidation JavaScript library



@ragdoll hit Hi there! No problem at all, I appreciate your response. I was actually referring to the FormValidation JavaScript library. I’m looking to implement it in my project and could use some guidance on setting it up. If you could provide an example, that would be really helpful! Thanks!


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(