Search by

lingmyat / mss-js-validation

Ling Myat Aung

This will validate request from blade without reload

Package info

github.com/LingMyat/MssJsValidationPackage

pkg:composer/lingmyat/mss-js-validation

Statistics

Installs: 217

Dependents: 0

Suggesters: 0

Stars: 4

Open Issues: 0

v1.1.4 2023-12-04 10:05 UTC

This package is auto-updated.

Last update: 2026-12-04 16:16:09 UTC


README

Show Laravel validation errors inline on Blade forms. The package reads the rules and messages from your FormRequest, checks the form over AJAX, and submits it to its regular action when the check passes.

Requirements

  • Laravel 9.x or 10.x
  • A full jQuery build with AJAX support. The example uses jQuery 3.7.1.

Installation

composer require lingmyat/mss-js-validation

Add the service provider to the existing providers list in config/app.php.

Lingmyat\MssJsValidation\MssJsValidationServiceProvider::class,

Publish the bundled JavaScript and CSS into public/vendor/mss-js-validation.

php artisan vendor:publish --tag=mss-js-validation

Validate a Blade form

This example uses a POST route named contacts.store and a StoreContactRequest with an email rule. Replace both with the route and request in your app.

{{-- In the page's <head> --}}
<meta name="csrf-token" content="{{ csrf_token() }}">
<link rel="stylesheet" href="{{ asset('vendor/mss-js-validation/css/mss-js-validation.min.css') }}">

{{-- In the page's <body> --}}
<form action="{{ route('contacts.store') }}" method="POST">
    @csrf

    <div>
        <label for="email">Email</label>
        <input id="email" name="email" type="email" value="{{ old('email') }}">
    </div>

    <button id="submit-btn" type="submit">Save contact</button>
</form>

<script src="https://code.jquery.com/jquery-3.7.1.min.js"
    integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="{{ asset('vendor/mss-js-validation/js/mss-js-validation.min.js') }}"></script>

{!! \Lingmyat\MssJsValidation\Facades\MssValidation::script([
    'request' => new \App\Http\Requests\StoreContactRequest(),
]) !!}

If your layout already loads jQuery, place the package script after it. To call MssValidation::script() by its short name, add the following entry to the existing aliases list in config/app.php.

'MssValidation' => Lingmyat\MssJsValidation\Facades\MssValidation::class,

Select2

If your form already uses Select2, add 'select2' => true alongside 'request' in the script options. For a single-select field, give the original <select> the select2 class so the package can style the enhanced control.

Integration details

  • Use one form per page. Match each input’s name to its validation rule key, and use id="submit-btn" on the submit button.
  • Use rules that can be serialized as JSON, such as pipe-delimited rule strings or arrays of strings. The package calls rules() and messages() on the request instance you pass in.
  • The bundled script sends its validation request to /mss-validation/validate at the site root.
  • Use your FormRequest on the actual submission route to validate and authorize each POST.

License

MIT. See the package on Packagist.