Finish the implementation of custom fields default values for checkboxes

This commit is contained in:
Ivan Nieto Vivanco 2022-02-09 13:12:42 -06:00
parent 2f3499e4b9
commit a36957dd77
3 changed files with 3 additions and 6 deletions

View file

@ -155,7 +155,6 @@ class AssetModelsController extends Controller
$model->requestable = $request->input('requestable', '0');
$this->removeCustomFieldsDefaultValues($model);
if ($request->input('custom_fieldset')=='') {
@ -464,8 +463,7 @@ class AssetModelsController extends Controller
foreach ($defaultValues as $customFieldId => $defaultValue) {
if(is_array($defaultValue)){
$model->defaultValues()->attach($customFieldId, ['default_value' => implode(',', $defaultValue)]);
}
if ($defaultValue) {
}elseif ($defaultValue) {
$model->defaultValues()->attach($customFieldId, ['default_value' => $defaultValue]);
}
}

View file

@ -47,7 +47,7 @@
<textarea v-if="field.type == 'textarea'" class="form-control" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'"></textarea><br>
<div v-for="field_value in field.field_values_array">
<input v-if="field.type == 'checkbox'" class="" type="checkbox" :name="'default_values[' + field.id + '][]'" :value="field_value"> <label>{{ field_value }}</label>
<input v-if="field.type == 'checkbox'" class="" type="checkbox" :name="'default_values[' + field.id + '][]'" :value="field_value" :checked="getValue(field).split(',').includes(field_value)"> <label>{{ field_value }}</label>
</div>
<select v-if="field.type == 'listbox'" class="form-control m-b-xs" :name="'default_values[' + field.id + ']'">

View file

@ -18,10 +18,9 @@
@elseif ($field->element=='checkbox')
<!-- Checkboxes -->
@foreach ($field->formatFieldValuesAsArray() as $key => $value)
<div>
<label>
<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"' : '') }}>
<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"' : (in_array($key, explode(',', $field->defaultValue($model->id))) ? ' checked="checked"' : '')) }}>
{{ $value }}
</label>
</div>