Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    add validators and get validators not possible

    To add validators on the client, it would be very useful to have a function like addValidators(). This is needed to add global validators( like a trim functionality) afterwards for all text fields for example.

    There is also a getValidators() needed, to check, if validators are there on generated fields, or do a formItem.setValidator(formItem.getValidators() .

    Can you intruduce a function like this?

    #2
    It's already there.

    Comment


      #3
      Nice, thanks

      Comment


        #4
        And how to use it?

        Lets say I have

        FormItem item = new FormItem();

        item.setValidator(new MaskValidator());
        // later on
        item.setValidator(new Validator().addValidatorDefinition("newvalidator", new Validator()));
        or
        item.setValidator(item.getValidators().addValidatorDefinition ...

        ?

        Comment


          #5
          It's a static method.

          Validator.addValidatorDefinition("myCustomValidatorType", new Validator());

          ... then in a .ds.xml file ...

          <field name="someName">
          <validator type="myCustomValidatorType" ...

          Comment


            #6
            Lets say I want to add a Trim-Validator, which iterates through all textfields, but all existing validators should work like before.

            Is Validator.addValidatorDefinition("myCustomValidato rType", new Validator());
            meant for something like that?

            I would prefer setting validators in my java code, without using the .ds.xml file, otherwise we need to set every validator we use on fields in the .ds.xml.

            Besides I want to set clientside validators related to the types of the datasourcefields.

            Is there another solution you are offering?
            Last edited by damend; 23 May 2011, 05:03.

            Comment


              #7
              That's simpler - just define a SimpleType that inheritsFrom the "text" built-in type, add the trim validator there, and use this type pervasively.

              Comment


                #8
                I did so. With this, both validators are executed. Nice !

                There is one issue left:
                The trim validator (used on the SimpleType) will change the value so that it will be trimmed,
                but it seems like the second customvalidator will use the original value without trimming.

                But the trimmed value has to be validated by the second validator, not the values before trimming.

                Do you have a solution for me ?

                Comment


                  #9
                  And:

                  1.) SimpleType validation will be executed on the client only, (if I don't execute a validation on the server explicity)
                  a custom validator, which is registered with Validator.addValidatorDefinition("myCustomValidato rType", new Validator());
                  and defined in the ds.xml, correct?

                  2.) Is it possible to pass arguments to custom defined validators in the datasource-definitionfile? How does the code looks like?
                  Is there an example?
                  Last edited by damend; 26 May 2011, 00:08.

                  Comment


                    #10
                    Yes - see the docs for CustomValidator - you can both look at the DataSourceField and at a Map of properties defined on the <validator> tag.

                    Comment


                      #11
                      On subsequent validators using the derived value - use setAttribute("resultingValue", value) to change the value used for further validation (and changed in the Record being validated). In the next nightly, this is shown as an official setResultingValue() API.

                      Comment

                      Working...
                      X