Field state is lost on save to JSON columns when invisible

Hi all. Not sure if I'm doing something wrong, but fields that are conditionally hidden using ->visible are getting nulled when saving them to a JSON column. For example let' say I have this:
Section::make('Test')
->schema([
Toggle::make('data.group1.enabled')
->label('Enabled')
->live(),

TextInput::make('data.group1.my_text')
->label('My text')
->visible(fn (Get $get) => $get('data.group1.enabled')),
Section::make('Test')
->schema([
Toggle::make('data.group1.enabled')
->label('Enabled')
->live(),

TextInput::make('data.group1.my_text')
->label('My text')
->visible(fn (Get $get) => $get('data.group1.enabled')),
If I already have something in the text field, then switch the toggle to off and re-save, the value in data.group1.my_text (the text field) is removed. It's as if the field value is set to null when ->visible() is false. Is that normal? I need to be able to hide the dependent field without losing the data on save. Any ideas?
1 Reply
binaryfire
binaryfire3mo ago
On further investigation, it looks like the values of hidden fields aren't present in the state. So I guess we have to merge the new and existing data before saving to JSON columns?