Reactive Builder field

Hello I want to create Builder field with lets say three blocks: - Hero - Footer - Header Is there a possibility to create for example reactive text input / placeholder that will fill whenever you Add a section in Builder field? I've tried to add reactive() and afterStateUpdate() in few places but I cant really get any effect
3 Replies
toeknee
toeknee17mo ago
Yeah just use a closure for setting and getting? afterStateUpdated(fn($state, Closure $set) => $set('myInput', $state))
Magikstah
MagikstahOP17mo ago
I've defined schema in my form like this:
TextInput::make('section_name')
->autofocus()
->reactive()
->afterStateUpdated(fn(\Closure $set) => $set('Test', 'test'))
->required(),

Builder::make('section_content')
->blocks([
Builder\Block::make('Image Carousel')
->schema([
Forms\Components\Repeater::make('slide')
->schema([
//inputs..
])
]),
])
->reactive()
->afterStateUpdated(fn(\Closure $set) => $set('Test', 'test'))
->maxItems(1)
])

Forms\Components\Group::make()
->schema([
Forms\Components\Section::make('Preview')->schema([
TextInput::make('Test')
->reactive(),
])
])
TextInput::make('section_name')
->autofocus()
->reactive()
->afterStateUpdated(fn(\Closure $set) => $set('Test', 'test'))
->required(),

Builder::make('section_content')
->blocks([
Builder\Block::make('Image Carousel')
->schema([
Forms\Components\Repeater::make('slide')
->schema([
//inputs..
])
]),
])
->reactive()
->afterStateUpdated(fn(\Closure $set) => $set('Test', 'test'))
->maxItems(1)
])

Forms\Components\Group::make()
->schema([
Forms\Components\Section::make('Preview')->schema([
TextInput::make('Test')
->reactive(),
])
])
Lets say my code looks like this (had to cut few things beacuse its too long but I think this should be enough) Changing value of Section Name text input changes Test input value to test like It's expected to, but adding block in block builder doesnt trigger any change, maybe i've put afterStateUpdated and reactive in bad place?
toeknee
toeknee17mo ago
Got ya, so it should be on the inputs really But... you will have to pass the value up with say: $set('./../Test',$state)
Want results from more Discord servers?
Add your server