Skip to content

FormValidator

Paweł Pastuszak edited this page Jan 9, 2015 · 13 revisions

FormValidator is a utility classes made for dialog that requires inputing various information and that information cannot be wrong. When input of any field in controlled form in invalid, accept button passed to FormValidaor will be disapled, and errorLabel text will be changed with error information. Demo

Currently FromValidator can check for following things:

  • Field is not empty
  • Path to file entered in text field points to existing (or not) file (or directory)
  • Path to file entered in text field points to existing (or not) file (or directory), but the file is relative to directory form other field.
  • Custom validator

Example (from the demo):

FormValidator validator = new FormValidator(createButton, errorLabel);

validator.notEmpty(projectRoot, "Project root path cannot be empty!");
validator.notEmpty(sourceLoc, "Source location cannot be empty!");
validator.notEmpty(assetsLoc, "Assets location cannot be empty!");

validator.fileExists(projectRoot, "Project folder does not exist!");
validator.fileExists(sourceLoc, projectRoot, "Source folder does not exist!");
validator.fileExists(assetsLoc, projectRoot, "Assets folder does not exist!");

BasicFormValidator

FormValidator uses functions that are not available on GWT (checking if file exist) that's why if you want your project to be GWT compatible use BasicFormValidator which provides only methods compatible with GWT.