- How do I integrate this package into an existing Laravel project using FormRequest validation?
- Install via Composer (`composer require proengsoft/laravel-jsvalidation`), publish the config if needed, then call `JsValidator::formRequest('YourFormRequest')` in your Blade template. The package auto-generates client-side validation rules matching your server-side FormRequest logic, including error messages and localization.
- Does this package support Laravel 13 and PHP 8.4?
- Yes, the package officially supports Laravel 11–13 and PHP 8.2–8.4. Check the [GitHub releases](https://github.com/proengsoft/laravel-jsvalidation/releases) for the latest compatibility updates. Always test in a staging environment before upgrading.
- What happens if a user submits a form with client-side validation disabled?
- The package relies on client-side validation for UX but falls back to server-side validation for security. If JavaScript is disabled, the form will still validate on the server using your existing Laravel validation logic (e.g., FormRequest). No additional configuration is needed.
- Can I use this package with Vue.js or React without jQuery?
- The package depends on jQuery Validation Plugin (v1.19.x), so it’s not ideal for modern SPAs. For Vue/React, consider alternatives like `vee-validate` or `laravel-vue-validation`. However, you can still use this package for traditional Laravel Blade forms while keeping SPAs separate.
- How do I handle AJAX validation errors (e.g., unique field conflicts) gracefully?
- The package automatically handles AJAX errors for rules like `unique`, `exists`, and custom rules by triggering server-side checks. For better UX, add loading states (e.g., disable submit buttons) and handle errors via the jQuery Validation Plugin’s `errorPlacement` or `showErrors` callbacks. Example: `$(form).validate({ onfocusout: false, onsubmit: false });`.
- Are there performance concerns with auto-generating JS validation scripts?
- The generated JS validation scripts are lightweight and only include rules defined in your FormRequest. For large forms, consider lazy-loading the validation script or using tree-shaking if bundling with Webpack/Vite. Test with tools like Lighthouse to measure impact.
- What if a custom validation rule isn’t supported client-side?
- Unsupported rules (e.g., `present`, `dateFormat` with timezones) will trigger server-side validation via AJAX. You can extend the package by adding custom JavaScript rules or use the `JsValidator::make()` method to manually define client-side rules for unsupported cases.
- How do I localize validation error messages for non-English forms?
- The package inherits Laravel’s localization system. Ensure your `resources/lang/` folders contain translated validation messages (e.g., `validation.php`). The client-side messages will automatically match your server-side translations. Test with `php artisan lang:publish` if messages are missing.
- Can I use this package with third-party validation packages like `spatie/laravel-validation-extensions`?
- Yes, the package supports third-party validation rules if they’re compatible with Laravel’s core validation system. Rules like `spatie/laravel-permission` or `laravel-validation-extensions` will work client-side if they’re implemented in JavaScript or via AJAX. Check the [supported rules list](https://github.com/proengsoft/laravel-jsvalidation#supported-rules) for updates.
- What’s the best way to test client-side validation in CI/CD?
- Test client-side validation by running JavaScript unit tests (e.g., with Jest or Karma) for custom rules and end-to-end tests (e.g., Cypress or Laravel Dusk) to simulate form submissions. Mock AJAX responses for rules like `unique` to avoid flaky tests. Example: `axios.mockResponse({ errors: { email: ['The email is already taken.'] } });`.