Search in sources :

Example 16 with WTextField

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

the class RegExFieldValidator_Test method setUp.

@Before
public void setUp() {
    field1 = new WTextField();
    field1.addValidator(new RegExFieldValidator(PATTERN, ERROR_MESSAGE));
    field2 = new WTextField();
    field2.addValidator(new RegExFieldValidator(PATTERN));
}
Also used : WTextField(com.github.bordertech.wcomponents.WTextField) Before(org.junit.Before)

Example 17 with WTextField

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

the class Validation_Test method testMandatorySpecificToUser.

@Test
public void testMandatorySpecificToUser() {
    UIContext uic1 = new UIContextImpl();
    UIContext uic2 = new UIContextImpl();
    List<Diagnostic> diags = new ArrayList<>();
    // uic 1 has mandatory check
    // uic 2 does not.
    WTextField textField = new WTextField();
    textField.setLocked(true);
    setActiveContext(uic1);
    textField.setMandatory(true);
    textField.validate(diags);
    Assert.assertEquals("UIC 1 should have a validation error", 1, diags.size());
    diags.clear();
    setActiveContext(uic2);
    textField.validate(diags);
    Assert.assertEquals("UIC 2 should not have a validation error", 0, diags.size());
}
Also used : UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 18 with WTextField

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

the class Validation_Test method testMandatoryMessage.

@Test
public void testMandatoryMessage() {
    List<Diagnostic> diags = new ArrayList<>();
    Diagnostic diag;
    // Test for standard message
    WTextField textField = new WTextField();
    textField.setMandatory(true);
    textField.validate(diags);
    Assert.assertEquals("Diags should contain mandatory validation error", 1, diags.size());
    diag = diags.get(0);
    Assert.assertTrue("Default validation error text should start with \"Please enter\"", diag.getDescription().startsWith("Please enter"));
    // Test mandatory message customisation
    textField.setMandatory(true, "Must have {0}.");
    diags.clear();
    textField.validate(diags);
    Assert.assertEquals("Diags should contain mandatory validation error", 1, diags.size());
    diag = diags.get(0);
    Assert.assertTrue("Incorrect custom error text", diag.getDescription().startsWith("Must have"));
}
Also used : ArrayList(java.util.ArrayList) Diagnostic(com.github.bordertech.wcomponents.validation.Diagnostic) WTextField(com.github.bordertech.wcomponents.WTextField) Test(org.junit.Test)

Example 19 with WTextField

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

the class WPanelTypeExample method setUpUtilBar.

/**
 * Add some UI to a "utility bar" type structure.
 */
private void setUpUtilBar() {
    utilBar.setLayout(new ListLayout(ListLayout.Type.FLAT, ListLayout.Alignment.RIGHT, ListLayout.Separator.NONE, false));
    WTextField selectOther = new WTextField();
    selectOther.setToolTip("Enter text.");
    utilBar.add(selectOther);
    utilBar.add(new WButton("Go"));
    utilBar.add(new WButton("A"));
    utilBar.add(new WButton("B"));
    utilBar.add(new WButton("C"));
    utilBar.setVisible(false);
}
Also used : ListLayout(com.github.bordertech.wcomponents.layout.ListLayout) WTextField(com.github.bordertech.wcomponents.WTextField) WButton(com.github.bordertech.wcomponents.WButton)

Example 20 with WTextField

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

the class WRadioButtonSelectExample method addAntiPatternExamples.

/**
 * Examples of what not to do when using WRadioButtonSelect.
 */
private void addAntiPatternExamples() {
    add(new WHeading(HeadingLevel.H2, "WRadioButtonSelect anti-pattern examples"));
    add(new WMessageBox(WMessageBox.WARN, "These examples are purposely bad and should not be used as samples of how to use WComponents but samples of how NOT to use them."));
    // Even compound controls need a label
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with no labelling component"));
    add(new ExplanatoryText("All input controls, even those which are complex and do not output labellable HTML elements, must be associated with" + " a WLabel or have a toolTip."));
    add(new WRadioButtonSelect("australian_state"));
    // submitOnChange is a WRadioButtonSelect no no!!
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with submitOnChange"));
    add(new ExplanatoryText("SubmitOnChange is bad in most cases but terrible with radio buttons because there is no way to change the selection" + " between non-contiguous options using the keyboard without having multiple page submits.\nIn the following example try to change " + "the selection from 'Outside Australia' to 'Queensland' using only your keyboard. To make this easier the WRadioButtonSelect has" + " an access key of 'M'"));
    final WRadioButtonSelect select = new SelectWithSelection("australian_state");
    final WTextField selected = new WTextField();
    selected.setReadOnly(true);
    select.setActionOnChange(new Action() {

        @Override
        public void execute(final ActionEvent event) {
            // does not matter what this is
            selected.setText(select.getValueAsString());
        }
    });
    select.setSubmitOnChange(true);
    // now put them all into the UI
    WFieldLayout layout = new WFieldLayout();
    add(layout);
    WField selectField = layout.addField("Make a selection to update the page", select);
    selectField.getLabel().setAccessKey('M');
    layout.addField("Selected option", selected);
    // Too many options anti-pattern
    add(new WHeading(HeadingLevel.H3, "WRadioButtonSelect with too many options"));
    add(new ExplanatoryText("Don't use a WRadioButtonSelect if you have more than a handful of options. A good rule of thumb is fewer than 10."));
    // use the country code list at your peril!!
    WRadioButtonSelect rbsTooBig = new WRadioButtonSelect(new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" });
    rbsTooBig.setButtonLayout(WRadioButtonSelect.LAYOUT_COLUMNS);
    rbsTooBig.setButtonColumns(6);
    rbsTooBig.setFrameless(true);
    rbsTooBig.setToolTip("Select your country of birth");
    add(rbsTooBig);
    // Don't use a radioButtonSelect if the user can make no selection unless you provide a null option
    add(new WHeading(HeadingLevel.H3, "Optional WRadioButtonSelect with no null option"));
    add(new ExplanatoryText("Once a radio button group has a selection it cannot be removed. If a WRadioButtonSelect is not mandatory it should" + " include a 'none of these' type null option.\nWhat happens if you make a selection in the following but then change your mind" + " (even ugly chairs are not your scene). To concentrate the mind I have made a selection for you."));
    WRadioButtonSelect noneOfTheAboveSelect = new SelectWithSelection(new String[] { "spike", "broken glass", "ugly chair", "wet paint" });
    noneOfTheAboveSelect.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    noneOfTheAboveSelect.setFrameless(true);
    layout = new WFieldLayout();
    add(layout);
    layout.addField("Where would you like to sit?", noneOfTheAboveSelect);
    // don't use a yes/no group of radio buttons for something which should be a checkbox
    add(new WHeading(HeadingLevel.H3, "Yes/No options"));
    add(new ExplanatoryText("If the only answers to your question is one of yes or no then you do not have a group of radio buttons, you have a check box.\n" + "In the following example the WRadioButtonSelect should be a WCheckBox and the label be 'I agree to the terms and conditions'"));
    layout = new WFieldLayout();
    add(layout);
    WRadioButtonSelect yesNoSelect = new WRadioButtonSelect(new String[] { "yes", "no" });
    yesNoSelect.setButtonLayout(WRadioButtonSelect.LAYOUT_FLAT);
    yesNoSelect.setFrameless(true);
    layout.addField("Do you agree to the terms and conditions?", yesNoSelect);
    add(new WHeading(HeadingLevel.H3, "No options"));
    add(new ExplanatoryText("An interactive WRadioButtonSelect with no options is rather pointless."));
    layout = new WFieldLayout();
    add(layout);
    layout.addField("Select from no options", new WRadioButtonSelect());
}
Also used : ValidatingAction(com.github.bordertech.wcomponents.validation.ValidatingAction) Action(com.github.bordertech.wcomponents.Action) WField(com.github.bordertech.wcomponents.WField) ActionEvent(com.github.bordertech.wcomponents.ActionEvent) WMessageBox(com.github.bordertech.wcomponents.WMessageBox) WFieldLayout(com.github.bordertech.wcomponents.WFieldLayout) ExplanatoryText(com.github.bordertech.wcomponents.examples.common.ExplanatoryText) WRadioButtonSelect(com.github.bordertech.wcomponents.WRadioButtonSelect) WTextField(com.github.bordertech.wcomponents.WTextField) WHeading(com.github.bordertech.wcomponents.WHeading)

Aggregations

WTextField (com.github.bordertech.wcomponents.WTextField)117 Test (org.junit.Test)90 SubordinateTarget (com.github.bordertech.wcomponents.SubordinateTarget)21 WCheckBox (com.github.bordertech.wcomponents.WCheckBox)21 WContainer (com.github.bordertech.wcomponents.WContainer)21 Equal (com.github.bordertech.wcomponents.subordinate.Equal)16 GreaterThanOrEqual (com.github.bordertech.wcomponents.subordinate.GreaterThanOrEqual)15 LessThanOrEqual (com.github.bordertech.wcomponents.subordinate.LessThanOrEqual)15 NotEqual (com.github.bordertech.wcomponents.subordinate.NotEqual)15 Rule (com.github.bordertech.wcomponents.subordinate.Rule)15 WSubordinateControl (com.github.bordertech.wcomponents.subordinate.WSubordinateControl)15 SubordinateTrigger (com.github.bordertech.wcomponents.SubordinateTrigger)14 WTextArea (com.github.bordertech.wcomponents.WTextArea)14 WComponentGroup (com.github.bordertech.wcomponents.WComponentGroup)12 WDropdown (com.github.bordertech.wcomponents.WDropdown)12 WButton (com.github.bordertech.wcomponents.WButton)11 WFieldLayout (com.github.bordertech.wcomponents.WFieldLayout)11 WHeading (com.github.bordertech.wcomponents.WHeading)10 WLabel (com.github.bordertech.wcomponents.WLabel)10 Hide (com.github.bordertech.wcomponents.subordinate.Hide)10