Based on select option set regex in text input field

Forms\Components\TextInput::make('code')
->required()
->maxLength(255), // need to add the regex for this
Forms\Components\Select::make('type')
->searchable()
->required()
->options(self::getBarcodeTypes()),
Forms\Components\TextInput::make('code')
->required()
->maxLength(255), // need to add the regex for this
Forms\Components\Select::make('type')
->searchable()
->required()
->options(self::getBarcodeTypes()),
2 Replies
Tieme
Tieme10mo ago
Take a look at https://filamentphp.com/docs/3.x/forms/advanced#form-component-utility-injection You can do this with a closure function like
Forms\Components\TextInput::make('code')
->required()
->maxLength(fn(Forms\Get $get):int => $get('type') == 'option_1' ? 100 : 150), // need to add the regex for this
Forms\Components\Select::make('type')
->searchable()
->required()
->live()
->options(self::getBarcodeTypes()),
Forms\Components\TextInput::make('code')
->required()
->maxLength(fn(Forms\Get $get):int => $get('type') == 'option_1' ? 100 : 150), // need to add the regex for this
Forms\Components\Select::make('type')
->searchable()
->required()
->live()
->options(self::getBarcodeTypes()),
dhanar98
dhanar98OP10mo ago
Hi @Tieme Thanks now it's working. working code is below :fi:
Forms\Components\TextInput::make('code')
->required()
->regex(fn(Forms\Get $get):string => self::getRegex($get('type'))),
Forms\Components\Select::make('type')
->searchable()
->required()
->live()
->options(self::getBarcodeTypes()),
Forms\Components\TextInput::make('code')
->required()
->regex(fn(Forms\Get $get):string => self::getRegex($get('type'))),
Forms\Components\Select::make('type')
->searchable()
->required()
->live()
->options(self::getBarcodeTypes()),
Want results from more Discord servers?
Add your server