F
Filament3w ago
Enas

Phone Input

Hello all, I have form that contains phone, mobile,city and country and I'm using ysfkaya/filament-phone-input plugin for phone field, now how to show the flag and country code based on selected country> is it possible? Thank you.
5 Replies
LeandroFerreira
what code did you try?
Mohamed Ayaou
Mohamed Ayaou3w ago
I think you are asking about how to update a field when another fields is changed, this is a general thing and here is an example from the docs: https://filamentphp.com/docs/3.x/forms/advanced#generating-a-slug-from-a-title
Mohamed Ayaou
Mohamed Ayaou3w ago
see also the docs of the plugin you use if it has a different way to set that phone number field state
Bruno Pereira
Bruno Pereira3w ago
If you make the country field reactive and on initialCountry method of the phone you check if the country field is filled, then you set it as the value of the country
Select::make('country')
->options([
...
])
->live(),

PhoneInput::make('mobile')
->label('Mobile phone')
->initialCountry(function(Get $get){
if ($get('country')) {
return $get('country');
}
// return a default value if empty
})
->required()
Select::make('country')
->options([
...
])
->live(),

PhoneInput::make('mobile')
->label('Mobile phone')
->initialCountry(function(Get $get){
if ($get('country')) {
return $get('country');
}
// return a default value if empty
})
->required()
keep in mind that the plugin expects country codes as valid values
Enas
EnasOP2w ago
thank you all.

Did you find this page helpful?