Open rabol opened 4 years ago
I have changed the 'view' for the checkboxes to this:
<div class="form-group row">
<div class="col-md-2 col-form-label text-md-right py-md-0">
{{ $field->label }}
</div>
<div class="col-md">
@foreach($field->options as $value => $label)
<div class="form-check">
<input
id="{{ $field->name . '.' . $loop->index }}"
type="checkbox"
class="form-check-input @error($field->key) is-invalid @enderror"
value="{{ $value }}"
wire:model.lazy="{{ $field->key . '.' . $loop->index }}">
<label class="form-check-label" for="{{ $field->name . '.' . $loop->index }}">
{{ $label }}
</label>
</div>
@endforeach
@include('laravel-livewire-forms::fields.error-help')
</div>
</div>
the change is: from
wire:model.lazy="{{ $field->key }}"
to
wire:model.lazy="{{ $field->key . '.' . $loop->index }}"
seems to work :)
please submit a pr, this is a good change
In setFormProperties() in the FormComponent class, the checkbox type is set with default value array. When this is changed so that checkboxes is set to array everything works.
public function setFormProperties($model = null) { $this->model = $model; if ($model) $this->form_data = $model->toArray(); foreach ($this->fields() as $field) { if (!isset($this->form_data[$field->name])) { $array = in_array($field->type, ['checkboxes', 'file']); $this->form_data[$field->name] = $field->default ?? ($array ? [] : null); } } }
First things first, thank you for this package, it has cut down significantly the development time for a box standard admin panel I needed planting in a project. Second, I can confirm that I hae the same issues mentioned in this issue and that @rabol's solution is working for me too.
In setFormProperties() in the FormComponent class, the checkbox type is set with default value array. When this is changed so that checkboxes is set to array everything works.
public function setFormProperties($model = null) { $this->model = $model; if ($model) $this->form_data = $model->toArray();
foreach ($this->fields() as $field) { if (!isset($this->form_data[$field->name])) { $array = in_array($field->type, ['checkboxes', 'file']); $this->form_data[$field->name] = $field->default ?? ($array ? [] : null); } } }
I can't see the diference from current code; furthermore, it didn't work for me. Am I missing something?
checkboxes is behaving strange:
my component:
When the form is displayed and I check one checkbox, all are selected