Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-4453

onError fires again when valid value is entered

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: Normal Normal
    • 9.5.0
    • 8.6.2
    • Components
    • Security Level: Jimmy
    • ZK 9.5.0 S1

      Steps to Reproduce

      run fiddle

      http://zkfiddle.org/sample/38pbkqf/1-on-error-fires-again-with-good-value

      enter "-1" (invalid) > get error, send on error

      enter "1" (valid) 

      Current Result

       clear error, send on error, send on change

      Expected Result

       clear error, send on change

      Debug Information

       https://github.com/zkoss/zk/blob/v9.1.0/zul/src/archive/web/js/zul/inp/InputWidget.js#L680

      em stores the error message

       

      https://github.com/zkoss/zk/blob/v9.1.0/zul/src/archive/web/js/zul/inp/InputWidget.js#L692-L693

      error message fired to server, even on correct value

      Workaround

      <script><![CDATA[
      zk.afterLoad("zul.inp", function () {
          var _xInputWidget = {};
          zk.override(zul.inp.InputWidget.prototype, _xInputWidget, {
              _validate: function (value) {
                  zul.inp.validating = true;
                  try {
                      var val = value, msg;
                      if (typeof val == 'string' || val == null) {
                          val = this.coerceFromString_(val);
                          if (val && ((msg = val.error) || val.server)) {
                              this.clearErrorMessage(true);
                              if (val.server || this._cst == '[c') { //CustomConstraint
                                  this._reVald = false;
                                  return {rawValue: value || '', server: true}; //let server to validate it
                              }
                              this._markError(msg, val);
                              return val;
                          }
                      }                //unlike server, validation occurs only if attached
                      if (!this.desktop) this._errmsg = null;
                      else {
                          var em = this._errmsg;
                          this.clearErrorMessage(true);
                          msg = this.validate_(val);
                          if (msg === false) {
                              this._reVald = false;
                              return {value: val, server: true}; //let server to validate it
                          }
                          if (msg) {
                              this._markError(msg, val);
                              return {error: msg};
                          }
                          this._reVald = false;
                          if (em){
                              console.log('prevented onError: ' + val);
                              //this.fire('onError', {value: val});
                          }
                      }
                      return {value: val};
                  } finally {
                      zul.inp.validating = false;
                  }
              }
           });
      });
      ]]></script>
      

       

            rudyhuang rudyhuang
            MDuchemin MDuchemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 4 hours
                4h
                Remaining:
                Time Spent - 3 hours Remaining Estimate - 1 hour
                1h
                Logged:
                Time Spent - 3 hours Remaining Estimate - 1 hour
                3h