-
Notifications
You must be signed in to change notification settings - Fork 538
Added min and max options #124
base: gh-pages
Are you sure you want to change the base?
Conversation
Added options to allow a min and max to be specified for the time. Only works in 24 hour mode
Hi Adam, Just been using this PR as part of a project that I'm working on, was glad to see that somebody had already thought of and had done work towards this requirement. Upon using this PR I found an issue with the minute validation, it appears that the minutes of the min hour are validated against the minutes of the max hour. I've made some minor changes to fix this and wondered if you would add them to the PR incase anybody else has this issue? From line 593: if (this.min || this.max) {
var ticks = this.minutesView.find('div.clockpicker-tick');
var tick,
tickValue;
if (!this.hours) {
this.hours = parseInt(this.spanHours.html());
}
if (!this.minutes) {
this.minutes = parseInt(this.spanMinutes.html());
}
if (!isHours && (this.hours === this.min[0])) {
// mark items as invalid for minutes if min hour applies
for (let i = 0; i < ticks.length; i++) {
tick = $(ticks[i]);
tickValue = parseInt(tick.html());
if (tickValue < this.min[1]) {
tick.addClass('invalid');
}
}
}
else if (!isHours && (this.hours === this.max[0])) {
// mark items as invalid for minutes if max hour applies
for (let i = 0; i < ticks.length; i++) {
tick = $(ticks[i]);
tickValue = parseInt(tick.html());
if (tickValue > this.max[1]) {
tick.addClass('invalid');
}
}
}
else {
for (let i = 0; i < ticks.length; i++) {
tick = $(ticks[i]);
tick.removeClass('invalid');
}
}
} |
Are you sure that is the case, the code you've provided seems to do exactly the same apart from it is separated into more lines? The content of
Are exactly the same and as such can be combined into
I don't think your code does anything differently to the current content apart from the below. As a result of looking at this I have noticed there is at least one bug in the code with incorrect use of the '=' instead of '==='. Specifically on line 602:
I think should be:
I've updated. I'm not sure if that fixes your issue or not however. Can you test with the updated code and if that doesn't work elaborate on your issue and provide me a simple repro for it? I can then have a look and try and fix the issue for you? If I've misunderstood something, happy to be corrected 😃 |
I came across this issue also that the minimum hour only allowed 00 minutes to be picked like the last hour only allows 00. DervishMarauders code helped, the equality operator fix didn't. |
Updates made as per suggestion from @DervishMarauder Co-Authored-By: Matthew Southern <[email protected]>
@Aphyxia @DervishMarauder I have updated to include the code provided by @DervishMarauder as it would seem that it solves the issues described by you both. Hopefully that's useful for someone else in the future. I am still unsure as to the difference if I'm honest, if someone feels like explaining I would appreciate it. |
Well, the problem is that when the hour is equal to the minimum hour, only the minute limitation of the minimum hour should be taken into account, therefore the statement |
@Aphyxia That makes sense, thanks for explaining 👍 |
Added options to allow a min and max to be specified for the time.
Only works in 24 hour mode