Handle old input

This commit is contained in:
Marcus Moore 2024-08-22 13:20:04 -07:00
parent d0a351a132
commit c3165717ed
No known key found for this signature in database

View file

@ -27,9 +27,6 @@ class CustomFieldSetDefaultValuesForModel extends Component
$this->fields->each(function ($field) { $this->fields->each(function ($field) {
$this->setSelectedValueForField($field); $this->setSelectedValueForField($field);
}); });
dump(old('default_values'));
dump($this->selectedValues);
} }
#[Computed] #[Computed]
@ -59,9 +56,11 @@ class CustomFieldSetDefaultValuesForModel extends Component
{ {
$defaultValue = $field->defaultValue($this->model_id); $defaultValue = $field->defaultValue($this->model_id);
// if we have old input for this field, use that instead // if old() contains a value for default_values that means
if (old('default_values.' . $field->id)) { // the user has submitted the form and we were redirected
// @todo: need to handle old input being null on purpose... // back with the old input.
// Let's use what they had previously set.
if (old('default_values')) {
$defaultValue = old('default_values.' . $field->id); $defaultValue = old('default_values.' . $field->id);
} }