Voyager: Add type "disabled" in field types

Created on 17 May 2017  路  10Comments  路  Source: the-control-group/voyager

  • Laravel Version: 5.4.x
  • Voyager Version: 0.10.11
  • PHP Version: 7
  • Database Driver & Version: 5

Description:

Would be great to have the field type as disable, for the cases we just want to show the value, but not allow to edit it. Or even to show it as text (not textfield)
Currentlty we need to validate IF field->name =='something" then apply the disable property, or with Jquery and look for the field and apply the property

Technical Debt feature help wanted

Most helpful comment

Hi Nuno,

You mean to disable the field just on edit? - that makes a lot of sense on the case some fields are allowed for insert but not edit.

All 10 comments

Hi Nuno,

You mean to disable the field just on edit? - that makes a lot of sense on the case some fields are allowed for insert but not edit.

@akazorg Exactly. For example I have some fields that comes from REST Api, so the ID's and titles can not be changed, but you can view the fields/values.
Setting the property as "disable" would allow to show the value preventing that it changes.
The best would be show it as text, so that the user can't mess up the source code and enable the field.

Currently what I'm doing is validate IF the field=="some_field" then show the value as simple text, and protecting the insert in DB using the [protect_fields]

Hello, Also want the same feature (add disabled attr to field).
need your guys help, thanks a lot.

This feature does not currently exist. PRs are welcome.

excellent feature to have, I was looking for the same, no disabling fields in json options.

I was looking the same,
So I was trying this,

  1. Overriding formField that you need
    App/resourses/view/vendors/voyager/formFields/override_custom_field
    In our formField we should copy, the field that we need from tcg/voyager/formFields

  2. Add a condition for disabled like json options (for example number field)
    I added this @if(isset($options->disabled)) disabled @endif

      <input type="number"
           class="form-control"
           name="{{ $row->field }}"
           type="number"
           @if($row->required == 1) required @endif
           @if(isset($options->disabled)) disabled @endif
           step="any"
           placeholder="{{ isset($options->placeholder)? old($row->field, $options->placeholder): $row->display_name }}"
           value="@if(isset($dataTypeContent->{$row->field})){{ old($row->field, $dataTypeContent->{$row->field}) }}@elseif(isset($options->default)){{ old($row->field, $options->default) }}@else{{old($row->field)}}@endif">
    
  3. In our bread details options of our field
    We add
    { "disabled": "something" }

I was looking the same,
So I was trying this,

  1. Overriding formField that you need
    App/resourses/view/vendors/voyager/formFields/override_custom_field
    In our formField we should copy, the field that we need from tcg/voyager/formFields
  2. Add a condition for disabled like json options (for example number field)
    I added this @if(isset($options->disabled)) disabled @endif
    <input type="number" class="form-control" name="{{ $row->field }}" type="number" @if($row->required == 1) required @endif @if(isset($options->disabled)) disabled @endif step="any" placeholder="{{ isset($options->placeholder)? old($row->field, $options->placeholder): $row->display_name }}" value="@if(isset($dataTypeContent->{$row->field})){{ old($row->field, $dataTypeContent->{$row->field}) }}@elseif(isset($options->default)){{ old($row->field, $options->default) }}@else{{old($row->field)}}@endif">
  3. In our bread details options of our field
    We add
    { "disabled": "something" }

Did you manage to get it to work using your method? Thanks

Yes, in Laravel 5.6 with Voyager 1.1. It is working very well

  • Here I added the bread details
    image
  • Here I added disabled option, also i changed name code for other purposes
    image

  • Example
    image

Hello,

Would be nice to have a readonly flag too. For slugified fields for example.
Cheers

@musthagon How did you manage to override it? I mean, I copied the same file, but I guess, Voyager doesn't know witch file to use. What should I do, if I want that Voyager uses my custom fieldForm and not the one that tcg provides?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rayqiri picture rayqiri  路  3Comments

TXRRNT picture TXRRNT  路  3Comments

abacram picture abacram  路  3Comments

wislem picture wislem  路  3Comments

winex01 picture winex01  路  3Comments