mdehoog / Semantic-UI-Calendar

Calendar module for Semantic UI
MIT License
805 stars 127 forks source link

disable certain days and time. [Feature request] #53

Closed Gsuz closed 7 years ago

Gsuz commented 7 years ago

Any chance you can add to skip certain days of the week. Let's say I only want selectable mon - fri from 08:00 to 16:00

mdehoog commented 7 years ago

This is provided through the isDisabled callback.

Gsuz commented 7 years ago

Can you give an example syntax? I can't get this to work.

The following works when the input value has a date already inserted by javascript but when no date is already entered I can't select any date.

isDisabled: function (date, mode) { if (date.getDay() == 6 || date.getDay() == 0 || date.getHours() < 8 || date.getHours() > 16) {return true} else {return false}; },

Error in console:

meteor.js:930 Exception from Tracker afterFlush function: meteor.js:930 TypeError: Cannot read property 'getDay' of undefined at Object.isDisabled (app.js:1667) at Object.date (modules.js:772) at Object.date (modules.js:772) at Object.initialize (modules.js:772) at HTMLDivElement.<anonymous> (modules.js:772) at Function.each (jquery.js:442) at jQuery.fn.init.each (jquery.js:194) at jQuery.fn.init.e.fn.calendar (modules.js:772) at Blaze.TemplateInstance.<anonymous> (app.js:866) at blaze.js:3397

Gsuz commented 7 years ago

Fixed the error with this workaround:

isDisabled: function (date, mode) { var check = function(){ if(date == undefined){ setTimeout(check, 200); // check again in 200ms } else { if (date.getDay() == 6 || date.getDay() == 0 || date.getHours() < 8 || date.getHours() > 17 ) {return true} else {return false}; } } return check(); },

There is probably a better way of doing this?

Gsuz commented 7 years ago

@mdehoog my above solution stopped working for me. I keep getting an error that variable "date" is undefined. Can you give me an example syntax?

arpadlukacs commented 7 years ago

I saw the undefined issue too and I just added that to make it go away:

if (date == undefined) return false;