Skip to content
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

Selected day "toggles" even though multidate is false #816

Closed
KaarloH opened this issue Feb 13, 2014 · 11 comments
Closed

Selected day "toggles" even though multidate is false #816

KaarloH opened this issue Feb 13, 2014 · 11 comments
Milestone

Comments

@KaarloH
Copy link

KaarloH commented Feb 13, 2014

When selecting already selected day (and multidate: false), it toggles it off and clears the input field. This can be very confusing especially if using autoclose feature.

@KaarloH
Copy link
Author

KaarloH commented Feb 13, 2014

Quick fix seems to be changing behaviour of _toggle_multidate -method at line 1015:

        _toggle_multidate: function(date){
            var ix = this.dates.contains(date);
            if (!date){
                this.dates.clear();
            }
            else if (ix == -1){
                this.dates.push(date);
            }
            else if ((typeof this.o.multidate === 'number' && this.o.multidate > 1) || this.o.multidate === true){
                this.dates.remove(ix);
            }
            if (typeof this.o.multidate === 'number')
                while (this.dates.length > this.o.multidate)
                    this.dates.remove(0);
        },

KaarloH added a commit to KaarloH/bootstrap-datepicker that referenced this issue Feb 13, 2014
When selecting already selected day (and multidate: false), it toggles it off and clears the input field. This can be very confusing especially if using autoclose feature.
@eternicode eternicode added this to the 1.3.1 milestone Feb 15, 2014
@kimbo6365
Copy link

This seems to already be discussed in #775

@eternicode says that a feature will be implemented in a coming release, which prevents the date from being deselected. In the meantime, I've implemented a quick workaround:

In the defaults @ line 1394, add a new option, allowDeselection

var defaults = $.fn.datepicker.defaults = {
    allowDeselection: false,
    ...
};

In the _toggle_multidate function @ line 1015, modify the "else if (ix !== -1)" statement to:

else if (ix !== -1 && this.o.allowDeselection){
            this.dates.remove(ix);
        }

@it-can
Copy link

it-can commented Mar 11, 2014

@kimbo6365 this works perfectly! PLEASE MERGE THAT FIX!!

@saiful
Copy link

saiful commented Mar 28, 2014

@kimbo6365 It works like a charm. I hope it can be merged. 👍

@fernandobritofl
Copy link

@kimbo6365 It's working!

@rohitranjan1991
Copy link

can anyone change this to the gitub repository so that it can be used with bower . Thanks in advance!!

@sarus
Copy link

sarus commented Apr 25, 2014

This issue should be merged with #873 as they relate to the same thing and two different PRs exist.

@frostney
Copy link

Works perfectly. Please merge this.

@n1ghtmare
Copy link

@kimbo6365 Outstanding, I hope this is merged ! 👍

@swatijoshi
Copy link

OSM! I was in trouble how I will achieve this without disturbing your code!
Please merge this same in your latest updates as well as in docs.It is very IMP option.
also add this same in #775
Thanks again :)

@acrobat acrobat modified the milestones: 1.3.2, 1.4.0 Dec 15, 2014
@acrobat
Copy link
Member

acrobat commented Dec 26, 2014

Fixed in #843

@acrobat acrobat closed this as completed Dec 26, 2014
@acrobat acrobat mentioned this issue Dec 26, 2014
6 tasks
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