Home > OS >  Disable dropdown in Laravel Blade
Disable dropdown in Laravel Blade

Time:10-04

I have this dropdown i want to make it read only or disable

 {{ Form::select('name[]',$names,$name : '' ,['class'=>'form-control name input_fields','readonly'=>true,'id'=>'name']) }}

tried disabled also

 {{ Form::select('name[]',$names,$name : '' ,['class'=>'form-control name input_fields','disabled'=>true,'id'=>'name']) }}

but i want to disable options only the option that is pre-selected should be saved in database, using readonly i can change the dropdown and using disable i can't get its value.

CodePudding user response:

This worked for me

# assume "$names" as your data array, which comes from the backend
@php
    $names = array('L' => 'Large', 'S' => 'Small')
@endphp

{{ Form::select('name[]',$names, '' ,['class'=>'form-control name input_fields','disabled'=>true,'id'=>'name']) }}

In form remove "$names,$name : ''" and run only with $names array

CodePudding user response:

You have to use a hidden input

Example based on your code ..

{{ Form::select('name_placeholder', $names, $name , ['class'=>'form-control name input_fields', 'readonly'=>true,' id'=>'name']) }}
{{ Form::hidden('name', $name) }}
  • Related