The errors component offers a versatile solution for handling and presenting errors within your application. It allows you to customize default error messages stored in language translation files, rendering errors returned by forms with ease, and even filtering these errors using either an array or a string separated by slashes. Furthermore, you have the power to adjust the component's header title and, similar to the alert component, modify or remove the associated icon as necessary. Additionally, you can assign a footer slot to enhance its functionality. In summary, the errors component is a flexible tool for managing and presenting errors in a way that suits your specific needs and preferences.
An effortless approach to utilizing the errors component involves rendering all errors that the form returns.
- The name field is required
- You must inform a valid email
- This address is invalid
- The phone field is required
1<x-errors />
The errors component provides the flexibility to filter the errors returned by the form. You can specify this filter by using either an array or a string separated by slashes.
- The name field is required
- You must inform a valid email
- This address is invalid
- The phone field is required
1<x-errors only="name|email" />2 3<x-errors :only="['address', 'phone']" />
You also possess the capability to modify the title that will be displayed in the header of the errors component.
- The name field is required
- You must inform a valid email
- This address is invalid
- The phone field is required
1<x-errors title="We found {errors} validation error(s)" />
Similar to the alert component, you have the flexibility to alter the icon or remove it as needed.
- The name field is required
- You must inform a valid email
1<x-errors only="name" iconless />2 3<x-errors only="email" icon="shield-exclamation" />
Additionally, drawing inspiration from the alert component, you can designate a footer slot.
- The name field is required
- You must inform a valid email
- This address is invalid
- The phone field is required
1<x-errors>2 <x-slot name="footer" class="flex items-center justify-end">3 <x-button sm label="Close" flat negative />4 </x-slot>5</x-errors>