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));
}
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());
}
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"));
}
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);
}
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());
}
Aggregations