Override method of zul.Upload in js

asked 2018-06-01 22:50:27 +0800

JustinFrost gravatar image JustinFrost
139 1 6

updated 2018-06-01 22:59:17 +0800

I am trying to override the error function on zul.Upload. My script is as follows:

zk.afterLoad("zul", function () {
    var _xUpload = {};
    zk.override(zul.Upload.prototype, _xUpload, {
        error : function(msg, uuid, sid) {
              // custom code here

No errors are thrown - but my custom code is never called. I am missing anything obvious here ? I have tried several ways based on documentation, but no luck.

My hope is to handle errors from uploads in a custom way, ie change the message and where they are displayed.

The above javascript is loaded globally.

Thanks for any help.

delete flag offensive retag edit

1 Answer

Sort by » oldest newest most voted

answered 2018-06-05 12:25:49 +0800

cor3000 gravatar image cor3000
3967 1 7
ZK Team

yes there's a slight oversight ... it's not really obvious but nevertheless important

You can test this yourself in the developer console:

-> undefined

-> ƒ (msg, uuid, sid) {
        var wgt = zk.Widget.$(uuid);
        if (wgt) {
            jq.alert(msg, {desktop: wgt.desktop, icon: 'ERROR'});
            zul.Upload.close(uuid, sid);

As you can see the error function is not on the prototype but at class level more like a static method.

You can see this in the source code: functions above this line are prototype functions (2nd parameter of zk.$extends), methods below are static defined on the class itself (3rd parameter).

Based on this information the way to override the static error method is this (omitting the prototype):

zk.afterLoad("zul", function () {
    var _xUploadStatic = {};
    zk.override(zul.Upload, _xUploadStatic, {
        error : function(msg, uuid, sid) {
              // custom code here

Then the method can be called in place of the original.

link publish delete flag offensive edit


Awesome thanks cor3000. Yes I did notice that debugging - I managed to get it working by using: zul.Upload.prototype.$class.error = function(...

JustinFrost ( 2018-06-07 13:20:27 +0800 )edit

FYI: zul.Upload.prototype.$class is identical to just zul.Upload so this is just shorter zul.Upload.error = function(...

cor3000 ( 2018-06-07 14:06:48 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools




Asked: 2018-06-01 22:50:27 +0800

Seen: 6 times

Last updated: Jun 05

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More