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

onError fires again when valid value is entered

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Normal
    • Resolution: Won't Fix
    • Affects Version/s: 8.6.2
    • Fix Version/s: 9.5.0
    • Component/s: Components
    • Security Level: Jimmy
    • Labels:
    • gh.sprint.customfield.default.name:
      ZK 9.5.0 S1

      Description

      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>
      

       

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  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