Added feature: Checkbox Custom Fields as list of values. (#9112)

* Added functionality for checkboxes in custom fields. Similar to how radio buttons work.

* Added the same functionality when the custom fieldset is encrypted.

* Added missing bits, so the edit custom assets view shows what values have been already stored in database
This commit is contained in:
Ivan Nieto 2021-02-16 19:20:29 -06:00 committed by GitHub
parent f89d789832
commit 12ff465cdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 8 deletions

View file

@ -165,10 +165,17 @@ class AssetsController extends Controller
foreach ($model->fieldset->fields as $field) {
if ($field->field_encrypted=='1') {
if (Gate::allows('admin')) {
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt($request->input($field->convertUnicodeDbSlug()));
}
if(is_array($request->input($field->convertUnicodeDbSlug()))){
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e(implode(', ', $request->input($field->convertUnicodeDbSlug()))));
}else{
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e($request->input($field->convertUnicodeDbSlug())));
} }
} else {
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
if(is_array($request->input($field->convertUnicodeDbSlug()))){
$asset->{$field->convertUnicodeDbSlug()} = implode(', ', $request->input($field->convertUnicodeDbSlug()));
}else{
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
}
}
}
}
@ -342,10 +349,18 @@ class AssetsController extends Controller
foreach ($model->fieldset->fields as $field) {
if ($field->field_encrypted=='1') {
if (Gate::allows('admin')) {
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e($request->input($field->convertUnicodeDbSlug())));
if(is_array($request->input($field->convertUnicodeDbSlug()))){
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e(implode(', ', $request->input($field->convertUnicodeDbSlug()))));
}else{
$asset->{$field->convertUnicodeDbSlug()} = \Crypt::encrypt(e($request->input($field->convertUnicodeDbSlug())));
}
}
} else {
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
if(is_array($request->input($field->convertUnicodeDbSlug()))){
$asset->{$field->convertUnicodeDbSlug()} = implode(', ', $request->input($field->convertUnicodeDbSlug()));
}else{
$asset->{$field->convertUnicodeDbSlug()} = $request->input($field->convertUnicodeDbSlug());
}
}
}
}

View file

@ -168,10 +168,10 @@
});
}).change();
// If the element is a radiobutton, doesn't show the format input box
// If the element is a radiobutton/checkbox, doesn't show the format input box
$(".field_element").change(function(){
$(this).find("option:selected").each(function(){
if (($(this).attr("value") != "radio")){
if (($(this).attr("value") != "radio") && ($(this).attr("value") != "checkbox")){
$("#format_values").show();
} else{
$("#format_values").hide();

View file

@ -21,7 +21,7 @@
<div>
<label>
<input type="checkbox" value="1" name="{{ $field->db_column_name() }}[]" class="minimal" {{ Request::old($field->db_column_name()) != '' ? ' checked="checked"' : '' }}>
<input type="checkbox" value="{{ $value }}" name="{{ $field->db_column_name() }}[]" class="minimal" {{ isset($item) ? (in_array($key, explode(', ', $item->{$field->db_column_name()})) ? ' checked="checked"' : '') : (Request::old($field->db_column_name()) != '' ? ' checked="checked"' : '') }}>
{{ $value }}
</label>
</div>