How to recover a data with Select2 in the registry edition?

Asked

Viewed 32 times

0

Follow the code of Lade, when I go to edit mode the corresponding data does not appear and yes Lect2 is empty.

<select name="cliente_id">
         <option value=""></option>
           @foreach ($clientes as $cliente )
              <option name="cliente_id" value="{{$cliente->id}}" 
           @if(old('cliente_id')==$cliente->id) {{'selected'}} @endif>
              {{$cliente->nome}}
           @endforeach
</select>

1 answer

0

There are two points to be observed:

1) In Editing the attribution with comparison using old() has to be verified via javascript using $(elemento).val();

2) If the above condition is working, after setting the value via Blade, you probably are starting with Select2, but the field still remains blank because you need to "update" the element because when vc iniciliza it loses the attribute "Selected" since a new component is embedded on the screen, as is easy to solve, just run a $(elemento).trigger('change'); that will work;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.