Best way to fill hint action data from component it is hinting from

Sorry if that doesn't really make sense but in the below code, I have a text box and a hint action on there, I need to be able to get the value of the text box to populate the options of the radio field in the action slideover, i have tried before form filled where i can get the value of connection but returning $data['directories'] as an array so ['test'=>'test'] does not fill this, when i do the options i need to be able to get this from the connection information. https://gist.github.com/sabuto/6d4ec88e7f1315ea1a12865357dc59b2
Gist
Test.php
Test.php. GitHub Gist: instantly share code, notes, and snippets.
15 Replies
mvenghaus
mvenghausβ€’3mo ago
you can get all the values via $get .. but if you want that the radio options are updated when you change the select .. then you have set ->live() to the select .. otherwise it renders too late
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
I tried to use $get see on line 22, i also tried just $get('connection') but it says connection is not found i think because it is a different form?
mvenghaus
mvenghausβ€’3mo ago
yeah .. didn't see there's another form .. but why you're using a differnt form there ?
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
so i have the main form, which is the connection etc i then want a folder picker on the ftp server so this action is the folder picker where it connects to the server and lists folders i will then use the selected folder as the value in the field
mvenghaus
mvenghausβ€’3mo ago
u could use events to communicate between them but also handle everything in 1 component
mvenghaus
mvenghausβ€’3mo ago
i tested i don't think it's the right way .. but it works Radio::make('directories')->options(function ($livewire) { dd($livewire->data['connection']); })
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
This works, however because the data is from a repeater it has the id which is randomly generated, so i need to figure out a way to grab that somehow, thank you for your help so far πŸ™‚ If i do beforeFormFilled on Action and do $get('connection;) it pulls it but i am unsure how to pass this along to the Action form I have tried injecting $data and assigning $data['connection'] to the value and then in the form of the form of the action passing $data but that can't resolve and then $get put that doesnt pull from the data
mvenghaus
mvenghausβ€’3mo ago
i think you don't have to pass it .. just access livewire in your action it should all be in the same state
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
so this is my problem, i need a way of grabbing it from the repeater
No description
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
where as if i do it here it grabs the right value
No description
mvenghaus
mvenghausβ€’3mo ago
so one of these tasks is upload to ftp und you want to check the connection for this? .. and the other tasks are differnt ? i do not really understand your concept
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
yes so i have tasks like this, I want to test the connection of the last repeater item in the image, the hint action is the code from the gist I hope this makes sense
No description
mvenghaus
mvenghausβ€’3mo ago
and if you click on test connection the directories should appear ? how about s.th like this
Forms\Components\Repeater::make('task')
->schema([
Forms\Components\Select::make('connection')
->options([1 => 'one', 2 => 'two'])
->default(2)
->live(),
Forms\Components\TextInput::make('location')
->hintAction(
Action::make('test')
->action(function(Get $get) {
dd($get('connection'));
})
),
Forms\Components\Fieldset::make('directories')
->schema(function(Get $get) {

$options = [];
if ((int)$get('connection') === 2) {
$options[] = 'foo';
}

return [
Forms\Components\Radio::make('selection')
->options($options)
];
})
->visible(fn(Get $get) => (int)$get('connection') === 2)

]),
Forms\Components\Repeater::make('task')
->schema([
Forms\Components\Select::make('connection')
->options([1 => 'one', 2 => 'two'])
->default(2)
->live(),
Forms\Components\TextInput::make('location')
->hintAction(
Action::make('test')
->action(function(Get $get) {
dd($get('connection'));
})
),
Forms\Components\Fieldset::make('directories')
->schema(function(Get $get) {

$options = [];
if ((int)$get('connection') === 2) {
$options[] = 'foo';
}

return [
Forms\Components\Radio::make('selection')
->options($options)
];
})
->visible(fn(Get $get) => (int)$get('connection') === 2)

]),
π•Ύπ–†π–ˆπ–—π–Šπ–’π–Šπ–“π–™π–šπ–˜
I could work with this thank you, it would mean i wouldn't need the hint action at all I don't think