Announcement

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

    dynamic control of validators

    1. SmartClient Version: v8.3p_2013-01-31/PowerEdition Deployment (built 2013-01-31)

    2. FF18, IE9

    Hi,

    I have some questions regarding usage of validators:

    For my UI for creation of customers with email field I've defined datasource.ds.xml file in wich I have the email field with regexp validator:

    <field name="email" type="textWithTrimming" required="true" length="100" operator="iContains" escapeHTML="true" customSelectExpression="usr.EMAIL">
    <validators>
    <validator type="regexp" expression="^([a-zA-Z0-9_.\-+])+@(([a-zA-Z0-9\-])+\.)+[a-zA-Z0-9]{2,4}$" errorMessage="invalidEmail"/>
    <validator type="lengthRange" min="1" max="100"/>
    </validators>
    </field>

    In this manner I want to obtain client+server validation provided automatically by the framework.

    Now I have another UI for searching customers, which should reuse the datasource.ds.xml but in that case I'd like to switch off the regex validator in terms of searching particular email addresses.

    Can I dynamically switch off the usage of the client+server regex validator? I want still to have the length validator.

    My temporary solution was to duplicate the field, once for creation and once for search what in my opinion isn't the best solution.

    Thanks in advance,
    zapryano

    #2
    You don't need to turn off the regexp validator in order to search. Validators are not applied to the criteria in a fetch request.

    However if you ever needed to do this, you could define a CustomValidator and add logic that decides whether to check the value with a regexp or skip the check.

    Comment


      #3
      Hi,

      of course I have to turned it off. I have two web pages, once for creation and once for searching, that means the input field "email" is present twice but the data source (*.ds.xml) exists only once and withn it is the regex validator.

      If I define CustomValidator and add logic to it so that for searching the regex validator ist not used, that means I have to remove the declarative xml regex validator. When I do it like this, shoud I write also the server validation on the code level right?

      Thanks,
      zapryano

      Comment


        #4
        Again, validators are not automatically enforced by the framework for search strings found in criteria. So you have no need to disable this validator for search - it is already inactive, atuomatically.

        Comment


          #5
          I've looked into the showcase:

          http://www.smartclient.com/smartgwt/showcase/#form_validation_regexp

          In the Overview on the right corner is written:

          "Enter a bad email address (eg just "mike") and press "Validate" to receive a validation error. The regular expression validator allows simple custom field types, with automatic enforcement on client on server."

          Is that really true --> "on client on server."

          I tried it out and I think the validation occures only on the client side.

          Comment


            #6
            While that is a capability of SmartGWT (shown here), it's not true of that sample. That sample demonstrates only client-side validation.

            This happened because the description was copied directly from the corresponding SmartClient sample, which actually *does* show single-source client and server validation. We'll fix the description.

            Comment

            Working...
            X