Show checkboxes a little less assy, actually save the data checked by them

This commit is contained in:
Ivan Nieto Vivanco 2022-02-09 10:49:10 -06:00
parent 796a0ebdaa
commit 2f3499e4b9
2 changed files with 7 additions and 2 deletions

View file

@ -168,7 +168,6 @@ class AssetModelsController extends Controller
}
}
if ($model->save()) {
return redirect()->route("models.index")->with('success', trans('admin/models/message.update.success'));
}
@ -463,6 +462,9 @@ class AssetModelsController extends Controller
private function assignCustomFieldsDefaultValues(AssetModel $model, array $defaultValues)
{
foreach ($defaultValues as $customFieldId => $defaultValue) {
if(is_array($defaultValue)){
$model->defaultValues()->attach($customFieldId, ['default_value' => implode(',', $defaultValue)]);
}
if ($defaultValue) {
$model->defaultValues()->attach($customFieldId, ['default_value' => $defaultValue]);
}

View file

@ -45,7 +45,10 @@
<div class="col-sm-12 col-lg-6">
<input v-if="field.type == 'text'" class="form-control m-b-xs" type="text" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'">
<textarea v-if="field.type == 'textarea'" class="form-control" :value="getValue(field)" :id="'default-value' + field.id" :name="'default_values[' + field.id + ']'"></textarea><br>
<input v-if="field.type == 'checkbox'" v-for="field_value in field.field_values_array" class="" type="checkbox" :value="field_value">
<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>
</div>
<select v-if="field.type == 'listbox'" class="form-control m-b-xs" :name="'default_values[' + field.id + ']'">
<option value=""></option>