Friday, February 28, 2014

How to disable smartgwt CustomValidator for a specific scenario

H
 

Hello,


I have a form which uses CustomValidator to check for non empty field whenever we try to Add a record (PARAMETER, VALUE) I'm looking for a way to disable form validation when I'm trying to Delete (the user can delete an empty listGridRecord if he changes his mind and needs no more to add).

I'm using this custom validator:

    CustomValidator validatorParameter = new CustomValidator() {            @Override          protected boolean condition(Object value) {                parameterName = (String) value;              if ((value == null || ((String) value).trim().isEmpty())) {                  rowIsValidate = false;                  return false;              } else {                  rowIsValidate = true;                  return true;              }          }      };

which I'm setting in an init() method this way:

parametersListGrid.getField(PARAMETER).setValidators(validatorParameter);

I tried setting a flag "noValidation" on true whenever I detect a click on Delete button and used it this way:

CustomValidator validatorParameter = new CustomValidator() {

        @Override          protected boolean condition(Object value) {                parameterName = (String) value;              if (((value == null || ((String) value).trim().isEmpty())) && !noValidation){                  rowIsValidate = false;                  return false;              } else {                  rowIsValidate = true;                  return true;              }          }      };

but I figured out that this flag is set later on after the validation happened so rowIsValidate stays false and we can't delete the empty record given the errors shown after validation;

Any idea on how to pass this validation step just in deletion scenario?

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment