1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    4
    Vote Rating
    0
    uuilee is on a distinguished road

      0  

    Default Custom validator comparing two fields

    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 - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      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
    uuilee is on a distinguished road

      0  

    Default


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

Thread Participants: 1

Tags for this Thread