|
Re: How to add Country Flag to phone number field [message #1840888 is a reply to message #1840825] |
Wed, 28 April 2021 08:30   |
Eclipse User |
|
|
|
Hi
The only country information that exists in AbstractPhoneNumberField is the "defaultCountryIsoCode". There's no standard way extend a country flag, but you could try to build an AbstractPhoneNumberBox which extends AbstractSequenceBox and is a composite of an AbstractPhoneNumberField and an AbstractImageField placed to the right of the phone-number-field. The image field displays a country-icon depending on the result of pnField#getDefaultCountryIsoCode(). Maybe you also need to override pnField#setDefaultCountryIsoCode to inform the image field the country has changed (unfortunately no property change event is fired in that method).
Now you can use the AbstractPhoneNumberBox as a replacement for the regular AbstractPhoneNumberField.
Hope that gives you some ideas. Cheers,
André
|
|
|
|
Re: How to add Country Flag to phone number field [message #1840932 is a reply to message #1840916] |
Thu, 29 April 2021 06:53   |
Eclipse User |
|
|
|
My bad: we use a PhoneNumberField in our projects which uses a package "org.eclipse.scout" but is closed source anyway (=wrong package name) :-(
So maybe I cannot provide you the source code for the field, but I can tell you how it works :-)
- The field extends AbstractStringField
- It has a String property 'countryIsoCode with the country ISO code (as returned by java.util.Locale#getCountry()
- It overrides validateValueInternal() and calls a PhoneNumberService to check if the entered phone-number is valid for the current country (as set by countryIsoCode)
- It overrides formatValueInternal() and calls a PhoneNumberService to format the entered phone-number when the user leaves the field
You must provide your own "PhoneNumberService". Of course the whole logic of parsing/formatting the string (number) in the PhoneNumberService is not trivial. So maybe its a good idea to check for a Java library which does that for you and call this library in your PhoneNumberService .
And if you must write your own PhoneField anyway, you could fire a PropertyChangeEvent when ever the countryIsoCode changes to update the ImageField with the country icon, as I outlined in my first post.
Cheers
André
|
|
|
|
|
|
Re: How to add Country Flag to phone number field [message #1844002 is a reply to message #1844001] |
Thu, 26 August 2021 16:44   |
Eclipse User |
|
|
|
By the way this is my code of the AstractPhoneCode
I understood that the String iso will be from the country field if I changed this value will change and then I should fire the event to update the imagefield but as the image field is part the the AbstractPhone field it does not appear in the UI and I have to make it in the initial Form so here I do not get the interest of reusable field if I can not combine ImageField and AbstractStringFiled for exemple, it means it works for UI basic UI field defined in Eclipse SDK and basic java type ( String , inti ...)
but when it comes to combining tow basic ui field of the eclipse SDK the UI does not runder the inner UI field ( in this case the ImageField
Thanks for your help
public abstract class AbstractPhoneField extends AbstractStringField {
private ImageField countryFlag;
private String countryIsoCode;
@FormData
public String getCountryIsoCode() {
return countryIsoCode;
}
@FormData
public void setCountryIsoCode(String countryIsoCode) {
this.countryIsoCode = countryIsoCode;
}
@Override
protected String validateValueInternal(String rawValue) {
return BEANS.get(IPhoneNumberService.class).validatePhoneNumber(countryIsoCode, rawValue);
}
@Override
protected String formatValueInternal(String value) {
return BEANS.get(IPhoneNumberService.class).formatPhoneNumber(countryIsoCode, value);
}
public ImageField getconfiguredCountryFlag(String countryiso) {
this.countryFlag.setAutoFit(true);
this.countryFlag.setImageId(countryiso);
return countryFlag;
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.05062 seconds