Bananas for the code monkey
It is always a good idea to prevent users from doing unwarranted things. Thats the whole idea of client side validation. (Client-side validation is one good way of catching errors before the code hits server, so....blah blah).
The general notion in UI is to accept user input using forms.(XSS, URL mangling etc left aside). In GXT, we can actually mandate/direct the hasty users to enter the correct data without cluttering the UI with error messages. The notion is simple, prevent the buttons from being enabled until all the validations are honored.
This is achieved using a
FormButtonBinding object. The actual code:
private FormPanel createLabelSearchPanel(String formHeader, String keywordLabel, String submitLabel) { FormPanel formPanel = new FormPanel(); formPanel.setLabelAlign(FormPanel.LabelAlign.RIGHT); formPanel.setHeading(formHeader); formPanel.setFieldWidth(DashboardConstants.FIELD_WIDTH); formPanel.setLabelWidth(DashboardConstants.LABEL_WIDTH); formPanel.setFrame(true); formPanel.setAutoHeight(true); FormData formData = new FormData("-10"); TextField<BaseModelData> textField = TextFieldFactory.getDefault().getTextField(keywordLabel, "(Enter Search Key)", ""); formPanel.add(textField, formData); Button searchButton = new Button(submitLabel, new SubmitButtonListener(formPanel)); formPanel.getButtonBar().add(searchButton); FormButtonBinding binding = new FormButtonBinding(formPanel); binding.addButton(searchButton); formPanel.setButtonAlign(HorizontalAlignment.CENTER); return formPanel; } ------------------------------------------
private TextField<BaseModelData> createTextField(final String fieldLabel, final String defaultText, final String defaultValue) { final TextField<BaseModelData> textField = new TextField<BaseModelData>(); textField.setFieldLabel(fieldLabel); textField.setEmptyText(defaultText); textField.setSelectOnFocus(true); textField.setAllowBlank(true); return textField; }
|
No comments:
Post a Comment