voyager icon indicating copy to clipboard operation
voyager copied to clipboard

Add type "disabled" in field types

Open nunomsh opened this issue 7 years ago • 16 comments

  • 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

nunomsh avatar May 17 '17 12:05 nunomsh

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 avatar May 30 '17 04:05 akazorg

@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]

nunomsh avatar May 31 '17 16:05 nunomsh

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

overcome avatar Aug 23 '18 03:08 overcome

This feature does not currently exist. PRs are welcome.

fletch3555 avatar Aug 23 '18 14:08 fletch3555

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

Benoit1980 avatar Sep 14 '18 17:09 Benoit1980

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"
    }
    

miguelangelmagdalena avatar Sep 19 '18 15:09 miguelangelmagdalena

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

Benoit1980 avatar Sep 20 '18 17:09 Benoit1980

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

miguelangelmagdalena avatar Sep 22 '18 12:09 miguelangelmagdalena

Hello,

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

axeloz avatar Oct 26 '18 13:10 axeloz

@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?

guillermoprojaslema avatar May 21 '19 20:05 guillermoprojaslema

@Benoit1980 now how to perform this Dynamically??suppose based on dropdown value?

Lambertn33 avatar Feb 08 '21 18:02 Lambertn33

@Benoit1980 now how to perform this Dynamically??suppose based on dropdown value?

I am very sorry but I gave up on Voyager, my app was struggling with constant bugs and I was finding it really difficult to customize it. Time for time, I prefer to code in pure Laravel and not waste time anymore with third party frameworks. If you count the amount of time you will put to learn each time a new framework....better just code in pure Laravel. Or you will spend your time looking for answers all the time. Trust me, I tried them all.

Benoit1980 avatar Feb 08 '21 20:02 Benoit1980

@if(isset($options->disabled) && !is_null($dataTypeContent->{$row->field})) disabled @endif

jcalistop avatar Aug 22 '22 18:08 jcalistop

@if(isset($options->disabled) && !is_null($dataTypeContent->{$row->field})) disabled @endif

It solved my problem! You can only disabled the input when you have dataTypeContent.

imsyuan avatar Oct 20 '22 02:10 imsyuan

I added a div id to my json for the field and called it "id=disabled_input" and then added a custom javascript file to the voyager config and then added this javascript: $("#disabled_input :input").attr('disabled', 'disabled');

All is good but if I save from the edit form it wipes out the form data on the POST Update for the input field haha. Guess I'll have to try the custom formField above :(

The struggle is real! Happy coding guys!!

chadpriddle avatar Feb 03 '23 03:02 chadpriddle

Found my solution! You can either do what I suggested above with Jquery but instead of adding a disabled attribute to the input you need to add the readonly attribute.

For more info on HTML requests with disabled attributes read this: https://stackoverflow.com/questions/7357256/disabled-form-inputs-do-not-appear-in-the-request

The custom formField described by @miguelangelmagdalena will also work but instead of @if(isset($options->disabled)) disabled @endif it should be @if(isset($options->disabled)) readonly="readonly" @endif

chadpriddle avatar Feb 03 '23 14:02 chadpriddle