Example usage for com.google.gwt.libideas.validation.client.validator DateRangeValidator DateRangeValidator

List of usage examples for com.google.gwt.libideas.validation.client.validator DateRangeValidator DateRangeValidator

Introduction

In this page you can find the example usage for com.google.gwt.libideas.validation.client.validator DateRangeValidator DateRangeValidator.

Prototype

public DateRangeValidator(Date min, Date max) 

Source Link

Document

Adds a min/max that the DataQuestion must conform to.

Usage

From source file:com.google.gwt.demos.validation.client.ValidationDemo.java

License:Apache License

/**
 * Create the sample booking form.//from   ww w.jav  a 2  s.  co  m
 */
private void createBookingForm() {

    // /////////////////////////////////////////////
    // World's most boring ui for a form.
    // ////////////////////////////////////////////
    booking = new FlexTable();
    booking.getColumnFormatter().setStyleName(0, "bookingLabel");
    RootPanel.get().add(booking);

    addTextField("Name");
    TextBox birth = addTextField("Birth");
    final TextBox crimeCode = addTextField("Crime Code");
    TextBox dateOfCrime = addTextField("Date of Crime");
    addTextField("Arresting Officer");
    TextBox phone = addTextField("Phone Number");

    // /////////////////////////////////////////////
    // Validation Support.
    // ////////////////////////////////////////////

    // Cannot book anyone younger than 18 or older than 100.
    Validator crimeValidator = new DateRangeValidator(offsetDate(100), offsetDate(18));
    ValidatorController crimeValidation = ValidatorController.addAsFocusListener(birth, crimeValidator);

    // Crime codes must be correctly formatted.
    ValidatorController.addAsFocusListener(crimeCode, crimeCodeFormatValidator);

    // Phone numbers can be pushed into shape if they are almost correctly
    // formatted.
    ValidatorController.addAsFocusListener(phone, new USPhoneValidator());

    // Creates a custom validator.
    Validator statuteValidator = createStatuteValidator(crimeCode);

    // Can add the same validator to multiple subjects to do multi-field
    // validation.
    crimeValidation.addValidator(statuteValidator);
    ValidatorController.addAsFocusListener(dateOfCrime, statuteValidator);

    // Cannot book someone for a crime more than 30 years old.
    ValidatorController.addAsFocusListener(dateOfCrime, new DateRangeValidator(offsetDate(30), new Date()));
}