#Function inside hiddenJs()?
16 messages · Page 1 of 1 (latest)
Use $get('email'), not document.getElementById('form.email').value
should be in the docs?
@gilded anchor Thanks for the reply. I'm trying to hidde/show based on a custom function, not just form elements values. The function returns bool, but can't get it to work. Probably should use afterStateUpdateJs()?
Hide tabs/inputs based on repeater item values.
But it does not work natively since Filament does not know which item to choose, because there are multiples. I have a function that will choose a value from the repeater's items (first/last/min/max/avg/count) and use this result in the JS expression.
`public static function configure(Schema $schema): Schema
{
return $schema
->components([
Repeater::make('items')
->schema([
TextInput::make('age')->required(),
]),
Tabs::make()
->schema([
Tabs\Tab::make('Adult')
->visibleJs(<<<'JS'
getEPCRValue('items.age',mode:'first')>= 18
JS
)
->schema([
TextInput::make('name'),
]),
]),
]);
}`
If you pass $get('items') in, you can then loop through the items to find the age you want?
I can already get the information I want with: getEPCRValue('items.age',mode:'first'). My issue is the result true/false not being evaluated. If I type: getEPCRValue('form.items.age',mode:'first')>= 18 on the console, it will return true, but the Tab/Input won't change display state.
if you do not pass in a reactive piece of state like with $get(), it will not reevaluate when the data changes
Something like this does not work: $get('items') && getEpcrInputValue('form.items.age',$get('items')) >= 18
If I add or remove an item from the repeater, it will reevaluate the data, like you said and works. But not when only changing the field value..
what is inside getEpcrInputValue
lots of manual checking of input values in there instead of using the values from $get
could be the cause of the issue
is the $get('items') supposed to make all child elements observable? Even if the function is only function getEpcrInputValue() {return 22;}, wont work when changing values.