Skip to content

Bug in option read #47

@glhfu2

Description

@glhfu2

I found a problem while reading plugin's options.

Calling the option method to read an option, like this:

var effects = $wizard.jWizard('option', 'effects');

It returns nothing.

The implementation of the option method in the plugin is the following:

    option: function (key, value) {
        if (this._superApply) {
            this._superApply(arguments);
        } else {
            if (arguments.length < 1 || key.indexOf(".") === -1) {
                $.Widget.prototype.option.apply(this, arguments);
            } else {
                var current = this.options,
                    path = key.split("."),
                    len = path.length - 1;

                $.each(path, function (x, part) {
                    if (x >= len) {
                        current[part] = value;
                    } else {
                        current = current[part];
                    }
                });

                this._setOption(path[0], value);
            }
        }
    },

Please note the call to superApply.

On third line, when it calls the superApply method "this._superApply(arguments)", it obviously doesn't return the option value in case of an option read (i.e. a call with only the key argument, and not the value argument).

It works correctly while setting an option.

I think the the implementation should be the following:

    option: function (key, value) {
        if (this._superApply) {
            return this._superApply(arguments);
        } else {
            if (arguments.length < 1 || key.indexOf(".") === -1) {
                $.Widget.prototype.option.apply(this, arguments);
            } else {
                var current = this.options,
                    path = key.split("."),
                    len = path.length - 1;

                $.each(path, function (x, part) {
                    if (x >= len) {
                        current[part] = value;
                    } else {
                        current = current[part];
                    }
                });

                this._setOption(path[0], value);
            }
        }
    },

So that the returned valued is returned back to the calling function.

Thank you for your work!

Best regards,

Marco

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions