Search in sources :

Example 1 with WPhoneNumberField

use of com.github.bordertech.wcomponents.WPhoneNumberField in project wcomponents by BorderTech.

the class SubordinateControlOptionsExample method setupTrigger.

/**
 * Setup the trigger for the subordinate control.
 */
private void setupTrigger() {
    String label = drpTriggerType.getSelected() + " Trigger";
    WFieldLayout layout = new WFieldLayout();
    layout.setLabelWidth(LABEL_WIDTH);
    buildControlPanel.add(layout);
    switch((TriggerType) drpTriggerType.getSelected()) {
        case RadioButtonGroup:
            trigger = new RadioButtonGroup();
            WFieldSet rbSet = new WFieldSet("Select an option");
            RadioButtonGroup group = (RadioButtonGroup) trigger;
            WRadioButton rb1 = group.addRadioButton("A");
            WRadioButton rb2 = group.addRadioButton("B");
            WRadioButton rb3 = group.addRadioButton("C");
            rbSet.add(group);
            rbSet.add(rb1);
            rbSet.add(new WLabel("A", rb1));
            rbSet.add(new WText("\u00a0"));
            rbSet.add(rb2);
            rbSet.add(new WLabel("B", rb2));
            rbSet.add(new WText("\u00a0"));
            rbSet.add(rb3);
            rbSet.add(new WLabel("C", rb3));
            layout.addField(label, rbSet);
            return;
        case CheckBox:
            trigger = new WCheckBox();
            break;
        case CheckBoxSelect:
            trigger = new WCheckBoxSelect(LOOKUP_TABLE_NAME);
            break;
        case DateField:
            trigger = new WDateField();
            break;
        case Dropdown:
            trigger = new WDropdown(new TableWithNullOption(LOOKUP_TABLE_NAME));
            break;
        case EmailField:
            trigger = new WEmailField();
            break;
        case MultiSelect:
            trigger = new WMultiSelect(LOOKUP_TABLE_NAME);
            break;
        case MultiSelectPair:
            trigger = new WMultiSelectPair(LOOKUP_TABLE_NAME);
            break;
        case NumberField:
            trigger = new WNumberField();
            break;
        case PartialDateField:
            trigger = new WPartialDateField();
            break;
        case PasswordField:
            trigger = new WPasswordField();
            break;
        case PhoneNumberField:
            trigger = new WPhoneNumberField();
            break;
        case RadioButtonSelect:
            trigger = new WRadioButtonSelect(LOOKUP_TABLE_NAME);
            break;
        case SingleSelect:
            trigger = new WSingleSelect(LOOKUP_TABLE_NAME);
            break;
        case TextArea:
            trigger = new WTextArea();
            ((WTextArea) trigger).setMaxLength(1000);
            break;
        case TextField:
            trigger = new WTextField();
            break;
        default:
            throw new SystemException("Trigger type not valid");
    }
    layout.addField(label, trigger);
}
Also used : WFieldSet(com.github.bordertech.wcomponents.WFieldSet) WNumberField(com.github.bordertech.wcomponents.WNumberField) WEmailField(com.github.bordertech.wcomponents.WEmailField) WPasswordField(com.github.bordertech.wcomponents.WPasswordField) WMultiSelect(com.github.bordertech.wcomponents.WMultiSelect) WLabel(com.github.bordertech.wcomponents.WLabel) WTextArea(com.github.bordertech.wcomponents.WTextArea) WRadioButton(com.github.bordertech.wcomponents.WRadioButton) WDropdown(com.github.bordertech.wcomponents.WDropdown) SystemException(com.github.bordertech.wcomponents.util.SystemException) WText(com.github.bordertech.wcomponents.WText) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) TableWithNullOption(com.github.bordertech.wcomponents.examples.common.ExampleLookupTable.TableWithNullOption) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WCheckBoxSelect(com.github.bordertech.wcomponents.WCheckBoxSelect) WMultiSelectPair(com.github.bordertech.wcomponents.WMultiSelectPair) WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) WSingleSelect(com.github.bordertech.wcomponents.WSingleSelect) RadioButtonGroup(com.github.bordertech.wcomponents.RadioButtonGroup) WCheckBox(com.github.bordertech.wcomponents.WCheckBox) WPartialDateField(com.github.bordertech.wcomponents.WPartialDateField) WDateField(com.github.bordertech.wcomponents.WDateField)

Example 2 with WPhoneNumberField

use of com.github.bordertech.wcomponents.WPhoneNumberField in project wcomponents by BorderTech.

the class WPhoneNumberFieldRenderer_Test method testRendererCorrectlyConfigured.

@Test
public void testRendererCorrectlyConfigured() {
    WPhoneNumberField textField = new WPhoneNumberField();
    Assert.assertTrue("Incorrect renderer supplied", getWebXmlRenderer(textField) instanceof WPhoneNumberFieldRenderer);
}
Also used : WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) Test(org.junit.Test)

Example 3 with WPhoneNumberField

use of com.github.bordertech.wcomponents.WPhoneNumberField in project wcomponents by BorderTech.

the class WPhoneNumberFieldRenderer_Test method testDoPaint.

@Test
public void testDoPaint() throws IOException, SAXException, XpathException {
    WPhoneNumberField field = new WPhoneNumberField();
    WButton button = new WButton();
    WSuggestions suggestions = new WSuggestions();
    WContainer root = new WContainer();
    root.add(field);
    root.add(button);
    root.add(suggestions);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getId(), "//ui:phonenumberfield/@id", field);
    assertXpathNotExists("//ui:phonenumberfield/@disabled", field);
    assertXpathNotExists("//ui:phonenumberfield/@hidden", field);
    assertXpathNotExists("//ui:phonenumberfield/@required", field);
    assertXpathNotExists("//ui:phonenumberfield/@readOnly", field);
    assertXpathNotExists("//ui:phonenumberfield/@minLength", field);
    assertXpathNotExists("//ui:phonenumberfield/@maxLength", field);
    assertXpathNotExists("//ui:phonenumberfield/@toolTip", field);
    assertXpathNotExists("//ui:phonenumberfield/@accessibleText", field);
    assertXpathNotExists("//ui:phonenumberfield/@size", field);
    assertXpathNotExists("//ui:phonenumberfield/@buttonId", field);
    assertXpathNotExists("//ui:phonenumberfield/@pattern", field);
    assertXpathNotExists("//ui:phonenumberfield/@list", field);
    field.setDisabled(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:phonenumberfield/@disabled", field);
    setFlag(field, ComponentModel.HIDE_FLAG, true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:phonenumberfield/@hidden", field);
    field.setMandatory(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:phonenumberfield/@required", field);
    field.setMinLength(45);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("45", "//ui:phonenumberfield/@minLength", field);
    field.setMaxLength(50);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("50", "//ui:phonenumberfield/@maxLength", field);
    field.setToolTip("tooltip");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getToolTip(), "//ui:phonenumberfield/@toolTip", field);
    field.setAccessibleText("accessible");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getAccessibleText(), "//ui:phonenumberfield/@accessibleText", field);
    field.setColumns(40);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("40", "//ui:phonenumberfield/@size", field);
    field.setDefaultSubmitButton(button);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(button.getId(), "//ui:phonenumberfield/@buttonId", field);
    field.setPattern("");
    assertSchemaMatch(field);
    assertXpathNotExists("//ui:phonenumberfield/@pattern", field);
    field.setPattern("test[123]");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getPattern(), "//ui:phonenumberfield/@pattern", field);
    field.setText("(12) 3456 7890");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(field.getText(), "normalize-space(//ui:phonenumberfield)", field);
    field.setSuggestions(suggestions);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo(suggestions.getId(), "//ui:phonenumberfield/@list", field);
    field.setPlaceholder("enter stuff here");
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("enter stuff here", "//ui:phonenumberfield/@placeholder", field);
}
Also used : WContainer(com.github.bordertech.wcomponents.WContainer) WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) WButton(com.github.bordertech.wcomponents.WButton) Test(org.junit.Test)

Example 4 with WPhoneNumberField

use of com.github.bordertech.wcomponents.WPhoneNumberField in project wcomponents by BorderTech.

the class WPhoneNumberFieldRenderer method doRender.

/**
 * Paints the given WPhoneNumberField.
 *
 * @param component the WPhoneNumberField to paint.
 * @param renderContext the RenderContext to paint to.
 */
@Override
public void doRender(final WComponent component, final WebXmlRenderContext renderContext) {
    WPhoneNumberField field = (WPhoneNumberField) component;
    XmlStringBuilder xml = renderContext.getWriter();
    boolean readOnly = field.isReadOnly();
    xml.appendTagOpen("ui:phonenumberfield");
    xml.appendAttribute("id", component.getId());
    xml.appendOptionalAttribute("class", component.getHtmlClass());
    xml.appendOptionalAttribute("track", component.isTracking(), "true");
    xml.appendOptionalAttribute("hidden", component.isHidden(), "true");
    if (readOnly) {
        xml.appendAttribute("readOnly", "true");
    } else {
        int cols = field.getColumns();
        int minLength = field.getMinLength();
        int maxLength = field.getMaxLength();
        String pattern = field.getPattern();
        WSuggestions suggestions = field.getSuggestions();
        String suggestionsId = suggestions == null ? null : suggestions.getId();
        WComponent submitControl = field.getDefaultSubmitButton();
        String submitControlId = submitControl == null ? null : submitControl.getId();
        xml.appendOptionalAttribute("disabled", field.isDisabled(), "true");
        xml.appendOptionalAttribute("required", field.isMandatory(), "true");
        xml.appendOptionalAttribute("minLength", minLength > 0, minLength);
        xml.appendOptionalAttribute("maxLength", maxLength > 0, maxLength);
        xml.appendOptionalAttribute("toolTip", field.getToolTip());
        xml.appendOptionalAttribute("accessibleText", field.getAccessibleText());
        xml.appendOptionalAttribute("size", cols > 0, cols);
        xml.appendOptionalAttribute("buttonId", submitControlId);
        xml.appendOptionalAttribute("pattern", !Util.empty(pattern), pattern);
        xml.appendOptionalAttribute("list", suggestionsId);
        xml.appendOptionalAttribute("placeholder", HtmlRenderUtil.getEffectivePlaceholder(field));
    }
    xml.appendClose();
    xml.appendEscaped(field.getText());
    if (!readOnly) {
        DiagnosticRenderUtil.renderDiagnostics(field, renderContext);
    }
    xml.appendEndTag("ui:phonenumberfield");
}
Also used : WComponent(com.github.bordertech.wcomponents.WComponent) WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) WSuggestions(com.github.bordertech.wcomponents.WSuggestions) XmlStringBuilder(com.github.bordertech.wcomponents.XmlStringBuilder)

Example 5 with WPhoneNumberField

use of com.github.bordertech.wcomponents.WPhoneNumberField in project wcomponents by BorderTech.

the class WPhoneNumberFieldRenderer_Test method testReadOnly.

@Test
public void testReadOnly() throws IOException, SAXException, XpathException {
    WPhoneNumberField field = new WPhoneNumberField();
    field.setReadOnly(true);
    assertSchemaMatch(field);
    assertXpathEvaluatesTo("true", "//ui:phonenumberfield/@readOnly", field);
}
Also used : WPhoneNumberField(com.github.bordertech.wcomponents.WPhoneNumberField) Test(org.junit.Test)

Aggregations

WPhoneNumberField (com.github.bordertech.wcomponents.WPhoneNumberField)6 Test (org.junit.Test)4 WSuggestions (com.github.bordertech.wcomponents.WSuggestions)2 RadioButtonGroup (com.github.bordertech.wcomponents.RadioButtonGroup)1 WButton (com.github.bordertech.wcomponents.WButton)1 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)1 WCheckBoxSelect (com.github.bordertech.wcomponents.WCheckBoxSelect)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WContainer (com.github.bordertech.wcomponents.WContainer)1 WDateField (com.github.bordertech.wcomponents.WDateField)1 WDropdown (com.github.bordertech.wcomponents.WDropdown)1 WEmailField (com.github.bordertech.wcomponents.WEmailField)1 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)1 WFieldSet (com.github.bordertech.wcomponents.WFieldSet)1 WLabel (com.github.bordertech.wcomponents.WLabel)1 WMultiSelect (com.github.bordertech.wcomponents.WMultiSelect)1 WMultiSelectPair (com.github.bordertech.wcomponents.WMultiSelectPair)1 WNumberField (com.github.bordertech.wcomponents.WNumberField)1 WPartialDateField (com.github.bordertech.wcomponents.WPartialDateField)1 WPasswordField (com.github.bordertech.wcomponents.WPasswordField)1