3

I want set read only field dynamically :

In Controller:

$is_read =true;

In Blade form:

{!!Form::text('name',$company_name,array('id'=>'rc_name','class'=>'form-control','placeholder'=>'Name','readonly'=>'$is_read'))!!}

Please help.

Govind Samrow
  • 9,981
  • 13
  • 53
  • 90

3 Answers3

4

Try This:

{!!Form::text('name',$company_name,array('id'=>'rc_name','class'=>'form-control','placeholder'=>'Name', $is_read ? 'readonly' : ''))!!}
3

The readonly attribute is a boolean attribute.

When present, it specifies that an input field is read-only.

A read-only input field cannot be modified (however, a user can tab to it, highlight it, and copy the text from it).

The readOnly property sets or returns whether a text field is read-only, or not. So readOnly="true" or readOnly="false" is not effected its working.

I've fixed it with following:

{!!Form::text('name',$company_name,array('id'=>'rc_name','class'=>'form-control','placeholder'=>'Name',$is_read ? 'readonly':''))!!}
Govind Samrow
  • 9,981
  • 13
  • 53
  • 90
0

You can add this to your input field in the blade

{{$is_read ? 'readonly':''}}

it could be something like below

<input type="text" class="input form-control" id="rc_name" name="rc_name" value="{{$company_name}}" {{$is_read ? 'readonly':''}} >

Omid Gharib
  • 301
  • 1
  • 9
  • 26