Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » How to add Country Flag to phone number field
How to add Country Flag to phone number field [message #1840825] Mon, 26 April 2021 08:22 Go to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Hello,
Does any one have any idea how to add a country flag to a phone number String Field ?
Kind Regards
Re: How to add Country Flag to phone number field [message #1840888 is a reply to message #1840825] Wed, 28 April 2021 08:30 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
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é


Eclipse Scout Homepage | Documentation | GitHub
Re: How to add Country Flag to phone number field [message #1840916 is a reply to message #1840888] Wed, 28 April 2021 17:33 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Thank you for the hint, but where can I find the AbstractPhoneNumberField ?
I do not find in client part
Re: How to add Country Flag to phone number field [message #1840932 is a reply to message #1840916] Thu, 29 April 2021 06:53 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
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é


Eclipse Scout Homepage | Documentation | GitHub
Re: How to add Country Flag to phone number field [message #1840939 is a reply to message #1840932] Thu, 29 April 2021 09:59 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Hello,
Thank you for your answer, I would like to get more information and if possible tutorial or training materials how to do extension like this to framework, is it possible to get some training documentation and if possible snippets ?
Kind Regards
Re: How to add Country Flag to phone number field [message #1840946 is a reply to message #1840939] Thu, 29 April 2021 11:04 Go to previous messageGo to next message
Andre Wegmueller is currently offline Andre WegmuellerFriend
Messages: 204
Registered: September 2012
Location: Baden-Dättwil, Switzerla...
Senior Member
Yes, Scout's "One Day Tutorial" covers the two topics that are relevant, in order to develop such a custom field:

1. Template Fields
https://eclipsescout.github.io/11.0/one-day-tutorial.html#sec-contacts_form_templatefields
The tutorial shows how to make a re-usable AbstractUrlImageField, which is quite similar to what I suggested in the first post here.

2. Services
The same tutorial also covers Scout's services, which you will need, when you want to implement the PhoneNumberService I suggested in my second post.
Take a look at the IPersonService in this chapter for instance. Basically you define an Interface for the service in your shared module, and provide an implementation of the interface in the server module. Just watch out that all objects your service uses (like method arguments) are Serializable.

You should probably also clone the GIT repo of the Contacts app to check how things are done there:
https://github.com/bsi-software/org.eclipse.scout.docs/tree/releases/11.0/code/contacts

With these concepts in mind, the rest is plain Java.

André



Eclipse Scout Homepage | Documentation | GitHub
Re: How to add Country Flag to phone number field [message #1844001 is a reply to message #1840946] Thu, 26 August 2021 16:29 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
Hello André;
One question : Is the ImageField part of the AbstractPhoneFiled or it is a separate field in the form ? :) this is important for me
Thanks
Re: How to add Country Flag to phone number field [message #1844002 is a reply to message #1844001] Thu, 26 August 2021 16:44 Go to previous messageGo to next message
Oueslati Anis is currently offline Oueslati AnisFriend
Messages: 128
Registered: June 2014
Location: Paris
Senior Member
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;
	}

}
Re: How to add Country Flag to phone number field [message #1852336 is a reply to message #1844002] Wed, 11 May 2022 07:49 Go to previous message
Karin Mitz is currently offline Karin MitzFriend
Messages: 1
Registered: May 2022
Junior Member
The phone number entry field is required in a web form where you need to collect information about a user's contact.
Previous Topic:High CPU when rendering data on TablePage
Next Topic:AbstractPageField for creating sub-forms
Goto Forum:
  


Current Time: Wed Jul 17 15:07:36 GMT 2024

Powered by FUDForum. Page generated in 0.04287 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top