Change background color if there is an error

Posted 3 years ago by angelorigo

Hi

I am trying to change a input type text background if there is a form submission error for that field :

{!! Form::text('phone', $employee->phone, ['autofocus', 'class' => ''])  !!}
    @if (count($errors) > 0)
      <span style="color:red">
              {!! $errors->first('phone') !!}
         </span>
     @endif

I try to insert into the class diretive but it does not work :

     {!! Form::text('phone', $employee->phone, ['autofocus', 'class' => '@if (count($errors) > 0 && $errors->first('phone')) background-color:red;  @endif'])  !!}
There is a way to change the background color if there is an error ?
                

Please sign in or create an account to participate in this conversation.