voyager
voyager copied to clipboard
Add type "disabled" in field types
- 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
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,
-
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
-
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">
-
In our bread details options of our field We add
{ "disabled": "something" }
I was looking the same, So I was trying this,
- 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
- 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">
- 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
-
Here I added disabled option, also i changed name code for other purposes
-
Example
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?
@Benoit1980 now how to perform this Dynamically??suppose based on dropdown value?
@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.
@if(isset($options->disabled) && !is_null($dataTypeContent->{$row->field})) disabled @endif
@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.
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!!
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