Home > Software design >  Laravel validator - how to return only errors for certain fields?
Laravel validator - how to return only errors for certain fields?

Time:04-13

I have one form in Laravel in which I have a couple of fields marked as "required" in validation rules in the controller. When the field is empty, Laravel highlights that field with red border and adds "is-invalid" CSS class (which is good). When the field is filled with anything, it adds a green border and "is-valid" CSS class.

However, for some fields, I would like to hide the green border when they're filled with something (success response) and only show the red border (failed response) when they're empty. Is there a way to silence the success response for some fields in the validator rules / controller?

CodePudding user response:

Your JavaScript code is adding a css class to your inputs like: 'is-valid', 'valid', 'other-valid-class'.

Just control by JavaScript when add the is-valid class.

Check your Script insert in the blade or the @section('scripts').

If in the controller your validations return a fail (on these input) should be shown as red border.

  • Related