tanthammar / tall-forms

Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.
https://github.com/tanthammar/tall-forms/wiki
MIT License
694 stars 86 forks source link

InputArray minItems and showEmptyItem functionality with Repeater #92

Closed shanakaperera closed 3 years ago

shanakaperera commented 3 years ago

As I have mentioned in the title, I am in need of an implementation to the Repeater which will initially appears with first row. (Actually single row is enough for my requirement here). And also the first row cannot be removed. Is it possible to perform such requirement with the current version of the project ? If not kindly guide me in this regard.

Thank you

tanthammar commented 3 years ago

Hi @shanakaperera

It is not available as a feature.

But it is easily achieved.

1.Set an empty array item as->default() to be displayed if the field value is empty.

Repeater::make('Your repeater')->fields([ your fields here ])->default([[]])

2.Use updatedFoo() hook to add an empty array again

public function updatedYourRepeater($value) {
    if(blank($value)) data_set($this, 'form_data.your_repeater', [[]]);
}
tanthammar commented 3 years ago

@shanakaperera I actually found a bug when testing what I suggested. It will be fixed in the next major release of Tall-forms. Until then you can manually alter the source-code. See this commit. https://github.com/tanthammar/tall-forms/commit/def83e812a46cb507768f7e4aafd94a39b576971