Results 1 to 3 of 3

Thread: How to make dynamic validation Constraints in a form?

  1. #1
    Join Date
    Jul 2010
    Posts
    19

    Default How to make dynamic validation Constraints in a form?

    How it's possible to make validation in a dynamic way?

    Example of validation:

    I have three form fields, filterType, low, high.

    low must be between 0 and 128
    high must be between 0 and 128
    filterType can be LOW, HIGH or BOTH

    if filterType is equal to "BOTH" low and high fields need to be validate
    if filterType is equal to "LOW" low field need be validate
    if filterType is equal to "HIGH" high field need be validate

    I need an approach to do it because i try everything I can imagine. Another detail, the fields low and high will be enable or disable in relation to filterType.

    Thanks in advance.

  2. #2
    Join Date
    Mar 2007
    Location
    Oudenaarde
    Posts
    294

    Default

    Add the following rules to your RulesSource when using a RulesValidator in your form:
    Code:
    Rules rules = new Rules(...);
    rules.add(new RequiredIfTrue("low", rules.any("filter", new Constraint[] {rules.eq("both"), rules.eq("low")})));
    rules.add(new RequiredIfTrue("high", rules.any("filter", new Constraint[] {rules.eq("both"), rules.eq("high")})));
    MSN: PM me please
    Skype: doclo_lieven

    Spring Rich Client Project Lead

  3. #3
    Join Date
    Jul 2010
    Posts
    19

    Default

    Quote Originally Posted by LievenDoclo View Post
    Add the following rules to your RulesSource when using a RulesValidator in your form:
    Code:
    Rules rules = new Rules(...);
    rules.add(new RequiredIfTrue("low", rules.any("filter", new Constraint[] {rules.eq("both"), rules.eq("low")})));
    rules.add(new RequiredIfTrue("high", rules.any("filter", new Constraint[] {rules.eq("both"), rules.eq("high")})));
    Thanks LievenDoclo but the point is validate the values of fields low and high between 0 and 128 when filterType change. BTW filterType is a combo.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •