Skip to content

FormValidator

intrigus edited this page Aug 23, 2015 · 13 revisions

FormValidator (source) 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 displayed, and errorLabel text will be changed with error information. Demo

Currently FormValidator 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
  • Value lesser or equal than
  • Value greater or equal than
  • Is integer number
  • Is float number

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!");

SimpleFormValidator

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 SimpleFormValidator which provides only methods compatible with GWT.