wvega / timepicker

A jQuery plugin to enhance standard form input fields helping users to select (or type) times
http://timepicker.co
GNU General Public License v2.0
216 stars 92 forks source link

[Feature request] Exclude given times from the dropdown #86

Open devhitech opened 8 years ago

devhitech commented 8 years ago

The timepicker works great with the min/maxTime/Hour/Minute to set the limits of the shown values.

However there's no option to add a gap/exclusion inside the set interval.

Example of the option (highlighted) I'm looking for:

$('#mytimepicker');.timepicker({
    timeFormat: 'HH:mm',
    interval: 60,
    minHour: 9,
    maxHour: 18,
    **exclude: 12, 15**
});

This would show a dropdown with all the hours between 9 and 18, except 12 and 15.

devhitech commented 8 years ago

I looked quickly over the JS code, and the following small change should do the trick (only works with 1 value in the exclude - for my particular use case it's fine for now - I called the option exHour, exHour: 12).

Inside _isValidTime: function(i, time) { having the exHour option added and the corresponding vars:

                if (i.options.exHour !== null) {
                    ex = normalize(i.options.exHour, null);
                }
                if (ex !== null) {
                    if (Date.parse(time) === Date.parse(ex)) {
                        return false;
                    }
                }

Would be nice to have this feature in the main release though.