Skip to content

FormValidator

Pawel Pastuszak edited this page Dec 7, 2018 · 13 revisions

FormValidator (source) is a utility class made for dialog that requires inputting various information and that information cannot be wrong. When input of any field in controlled form is invalid, accept button passed to FormValidator will be disabled and errorLabel text will be changed to 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 from another 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.