Announcement

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

    ValidatorType.MASK also serverside question

    Hi Isomorphic,

    the docs for ValidatorType.MASK mention:
    If validation is successful a transformation can also be specified via the validator.transformTo property. This should be set to a string in the standard format for string replacement via the native JavaScript replace() method.
    I have a serverside custom validator that does not more than
    Code:
    public class ValidatorSetStringToUppercase {
        public boolean condition(Object value, Validator validator, String fieldName, Map<Object, Object> record, DataSource ds,
                DSRequest request, HttpServletRequest httpServletRequest, ValidationContext validationContext) throws Exception {
            validationContext.setResultingValue(value != null ? value.toString().toUpperCase() : value);
            return true;
        }
    }
    Could I also do this with less code with a mask-validator or does the mask-validator only run client side?
    It mentions JavaScript, so I'm not sure here. Either way, a clarification in the docs would help here.

    And out of interest, what would be the best and most declarative way to make a value uppercase? I could also imagine doing this with a customUpdateExpression for example.

    Best regards
    Blama

    #2
    Other than specific characters known in advance (like in an ID of the form “u” followed by several numbers, canonicalizing the leading “u” to an uppercase “U”), there is no way to use a regexp replace to transform to uppercase.

    The most declarative way this could currently be done is to use a regexp validator plus a one-line Server Script to do the uppercasing.

    Comment


      #3
      Hi Isomorphic,

      you could do something like
      Validate: ^(.*)$
      Replace: \U\1

      But only if the mask-validator also runs on the server.

      Out of interest: What would the server script look like?

      Best regards
      Blama

      Comment


        #4
        Originally posted by Blama View Post
        And out of interest, what would be the best and most declarative way to make a value uppercase? I could also imagine doing this with a customUpdateExpression for example.
        Hi Blama, you may do something like that:
        https://forums.smartclient.com/forum...094#post241094

        Comment


          #5
          Hi claudiobosticco,

          thanks. That's what I'm doing now (see #1). I was wondering if this was also possible more decoratively without code after seeing that mask-validators also support transform.
          And as this transform happens to be possible with RegExp IMHO, this would work if mask-validators also run serverside. The docs are not clear on this (by only mentioning "JavaScript", not "Java"), so I started this thread.

          Best regards
          Blama

          Comment


            #6
            Blama Okay, sorry, I didn't read carefully the code, maybe I'm still a bit shaken by the announcement of upcoming AI news in another thread ;-)

            Comment


              #7
              claudiobosticco haha, me too.

              Already tried these APIs in the 13.1d showcase, but nothing to see so far.

              Best regards
              Blama

              Comment

              Working...
              X