input-moment icon indicating copy to clipboard operation
input-moment copied to clipboard

Add isValid callback prop to allow locking dates

Open rstrand opened this issue 8 years ago • 2 comments

I have added an isValid callback which enables you to lock certain dates. This should be part of what issue #2 is asking.

I have had to change the standard behaviour slightly so that changing the month in the calendar view doesn't automatically update the date selected by the component until you actually click on a new date. This is to avoid a locked date becoming selected when the month is changed and allow you to navigate through an entirely locked month.

The isValid callback should look something like this:

function isValid(m) {
  // Disable weekends
  return m.day() != 0 && m.day() != 6;
}

rstrand avatar Jun 07 '16 15:06 rstrand

@rstrand note there is a behavior change in this implementation, in that currently the moment object that's been passed in gets mutated vs cloned.

Now, i dont know if the author intends/desires the mutation aspect.

however, I updated this logic into the latest input-moment, and can be found here: https://github.com/aikar/input-moment/commit/0523d8144490e37c0938a0511aebe80e3443f943

And also preserves the mutation logic by only cloning on test cases and doesnt use the state for month as you were doing.

@wangzuo this is a pretty critical functionality need for any user of this component, so i hope you can get my version in (As i said in the other issue, i'm under super time crunch mode so i dont have the time to split my changes into separate PR's)

aikar avatar Feb 24 '17 09:02 aikar

I've rebased this pull request on the current master

rstrand avatar Dec 12 '18 21:12 rstrand