-
Notifications
You must be signed in to change notification settings - Fork 17
WPhoneNumberField
WPhoneNumberField is a component for creating an input field with specific input type for telephone numbers.
For further information see WTextField; the remainder of this document is concerned with differences between WPhoneNumberField and WTextField.
- Why use WPhoneNumberField
- Accessibility
- Appearance
- HTML output
- Read only
- Input pattern
- Testing
- Related components
- Further information
WPhoneNumberField should be used whenever user input of a telephone number is required as it will provide users with soft keyboards the ability to use a phone number keyboard. When in the read-only state WPhoneNumberField will output a link which can invoke a soft phone if available or dial a mobile phone if allowed by the user.
WPhoneNumberField enhances accessibility by providing phone number enhanced input where possible.
See accessibility notes of WTextField as they all apply to WPhoneNumberField.
The appearance of the WPhoneNumberField is dependent on the user agent. The illustrations in this document were all created using Google Chrome on OS X.
-
a WPhoneNumberField with no input
-
a WPhoneNumberField with user input
-
a WPhoneNumberField with content in a read-only state
A WPhoneNumberField (when not in a read-only state) will output a wrapping a HTML input element in the telephone state. This is an interactive, form bound control and therefore may not be used in any context where the content model forbids this content category. At the moment there is no validation or customisation of input for WPhoneNumberField compared with WTextField.
If in a read-only state the output will be a HTML a element containing the text value of the component as a tel:
protocol link (see RFC3966).
See WTextField. When in the readOnly state WPhoneNumberField will output a HTML a
element which can invoke a soft phone if available or dial a mobile phone if allowed by the user.
-
a WPhoneNumberField with content in a read-only state
WPhoneNumberField supports setting an input pattern. It is strongly recommended that one does not attempt to set a pattern for phone number unless one has a limited (and non-international) audience for the application. Telephone number RegExps are not particularly complex but the lack of back-lookups in JavaScript regexs makes them mostly unworkable.
WPhoneNumberField may be tested using the com.github.bordertech.wcomponents.test.selenium.element.SeleniumWPhoneNumberFieldWebElement
extension of org.openqa.selenium.WebElement
.
The best way to get a WEmailField from a test view is by using SeleniumWComponentsWebDriver which has a method findWPhoneNumberField(By)
. This can be used in conjunction with com.github.bordertech.wcomponents.test.selenium.ByLabel
, for example, to find a WPhoneNumberField using its label's text.
@Test
public void testFindByLabel() {
SeleniumWComponentsWebDriver driver = getDriver();
String labelText = "Phone";
SeleniumWPhoneNumberFieldWebElement field =
driver.findWPhoneNumberField(new ByLabel(labelText, false));
Assert.assertNotNull("Unable to find phone number field by label text",
field);
}
For more information on members provided by SeleniumWWPhoneNumberFieldWebElement
see:
- JavaDoc;
- HTML Specification;
- [RFC3966 tel URI](RFC3966
- List of WComponents.