Results 1 to 3 of 3

Thread: Custom validator comparing two fields

  1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    4
    Vote Rating
    0
      0  

    Default Custom validator comparing two fields

    I have two DateFields, startDate and endDate.
    I want to write a validator that checks that startDate should be smaller than endDate and vice versa.

    The Validator interface however only accepts one field and one value.
    What's the best way to implement the this check?

  2. #2
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737
    Vote Rating
    93
      1  

    Default

    One option would be to make the validator implementation's constructor accept as an argument the second field to compare against. Then, make a new instance of the validator for each field, pointing at the corresponding field that it needs to work with to behave correctly.

    Another option would be to just make an anonymous subclass, and as long as the other field is made final (or an instance variable), refer to it within the implementation.

  3. #3
    Sencha User
    Join Date
    Nov 2012
    Posts
    4
    Vote Rating
    0
      0  

    Default

    Thanks, solved by putting the required fields into the constructor.

Tags for this Thread

Posting Permissions

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