Skip to content

Option getter always returns the source jquery object (1.0.2, 1.0.3, ..., 1.4.4) #434

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rbeurskens opened this issue Sep 17, 2012 · 4 comments

Comments

@rbeurskens
Copy link

When requesting an option that is not 'getDate' , the query object itself is returned instead of the value(s) of the requested option.

suggested fix ( don't know if it is bulletproof ):

$.fn.extend({
    //########################################################################
    // shorthand just to use timepicker..
    //########################################################################
    timepicker: function(o) {
        o = o || {};
        var tmp_args = arguments;

        if (typeof o == 'object') { tmp_args[0] = $.extend(o, { timeOnly: true }); }

        var result = $(this).map(function() {        //  <---
            return /* <---- */ $.fn.datetimepicker.apply($(this), tmp_args); 
        });
        return (result[0]==$(this)[0]) ? result : result[0]; // <---

    },

    //########################################################################
    // extend timepicker to datepicker
    //########################################################################
    datetimepicker: function(o) {
        o = o || {};
        var tmp_args = arguments;

        if (typeof(o) == 'string'){
            if(o == 'getDate' /**/ ||  (o == 'option' && tmp_args.length == 2 && typeof (tmp_args[1]) == 'string')) /*<---*/) {
                return $.fn.datepicker.apply($(this[0]), tmp_args);
            }
            else {
                    return  = this.each(function () { 
                        $(this).datepicker.apply($t, tmp_args);  
                    });
            }
        }
        else {
            return this.each(function() {
                var $t = $(this);
                $t.datepicker($.timepicker._newInst($t, o)._defaults);
            });
        }
    }
});
@rbeurskens
Copy link
Author

(issue also confirmed for 1.0.3)

applied a fix to the suggested fix:
return (o == 'option' && tmp_args.length == 2 && typeof (tmp_args[1]) == 'string') ? result : this ;

@rbeurskens
Copy link
Author

finally applied a working getter for 'options' (assuming the are no other getters apart from 'getDate')

@rbeurskens
Copy link
Author

Still applies to latest (1.4.4). Should I use a pull request? (note: added code is just copy/paste from similar lines in jQuery UI Datepicker widget, which does have a getter for options)

        /*
        * extend timepicker to datepicker
        */
        datetimepicker: function (o) {
            o = o || {};
            var tmp_args = arguments;

            if (typeof(o) === 'string') {
/*--*/          if (o === 'getDate' ) {
/*++*/          if (o === 'getDate'  || (o === 'option' && tmp_args.length === 2 && typeof (tmp_args[1]) === 'string')) {
                    return $.fn.datepicker.apply($(this[0]), tmp_args);
                } else {
                    return this.each(function () {
                        var $t = $(this);
                        $t.datepicker.apply($t, tmp_args);
                    });
                }
            } else {
                return this.each(function () {
                    var $t = $(this);
                    $t.datepicker($.timepicker._newInst($t, o)._defaults);
                });
            }
        }
    });

@rbeurskens rbeurskens changed the title Option getter always returns the source jquery object (1.0.2, 1.0.3) Option getter always returns the source jquery object (1.0.2, 1.0.3, ..., 1.4.4) May 19, 2014
@trentrichardson
Copy link
Owner

@rbeurskens thanks for this, sorry it has taken so long, I managed to get buried in requests and issues..

It is in dev now and I want to get a new stable version within the week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants