protonemedia / laravel-splade

💫 The magic of Inertia.js with the simplicity of Blade 💫 - Splade provides a super easy way to build Single Page Applications (SPA) using standard Laravel Blade templates, and sparkle it to make it interactive. All without ever leaving Blade.
https://splade.dev
MIT License
1.47k stars 111 forks source link

Splade Input Errors based on Label attribute #491

Closed SebRothIFB closed 1 year ago

SebRothIFB commented 1 year ago

Description:

Is there a way to show validation errors based on Label attribute in x-splade-input?

`

                        <x-splade-input name="BookingNumber" label="Booking number*" />
                        <x-splade-select name="FCL_LCL" label="FCL or LCL? *" :options="[1 => 'FCL', 2 => 'LCL']" choices />

`

image

thecyrilcril commented 1 year ago

@SebRothIFB do you mean use the label value FCL or LCL in the returned error message?

If that's what you want you would do that on the backend. you could create a form request with an attributes method like below:

    public function attributes()
    {
        return [
            ...
            'FCL_LCL' => 'FCL or LCL',

        ];
    }

You error message will return "The FLC or LCL field is required" Hopefully that what you wanted.

SebRothIFB commented 1 year ago

@thecyrilcril

Thanks for the help and the good advice! That helped me a lot.