#Function inside hiddenJs()?

16 messages · Page 1 of 1 (latest)

light hullBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

gilded anchor
#

Use $get('email'), not document.getElementById('form.email').value

#

should be in the docs?

carmine bramble
#

@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()?

gilded anchor
#

what are you trying to do

#

specifically

carmine bramble
#

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'),
                        ]),
                ]),
        ]);
}`
gilded anchor
#

If you pass $get('items') in, you can then loop through the items to find the age you want?

carmine bramble
#

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.

gilded anchor
#

if you do not pass in a reactive piece of state like with $get(), it will not reevaluate when the data changes

carmine bramble
#

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..

gilded anchor
#

what is inside getEpcrInputValue

carmine bramble
gilded anchor
#

lots of manual checking of input values in there instead of using the values from $get

#

could be the cause of the issue

carmine bramble
#

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.