Published
Edited
Jun 23, 2021
Insert cell
md`# Testing Date Inputs in Observable`
Insert cell
today = d3.timeFormat("%Y-%m-%d")(new Date(Date.now()))
Insert cell
Insert cell
viewof pastDate = Inputs.text({
type: "date",
label: html`<b>A Date in the Past</b>`,
max: "2021-06-15",
value: today
})
Insert cell
md` However it lets me select future dates and thinks they are valid`
Insert cell
[pastDate, viewof pastDate.checkValidity()]
Insert cell
viewof futureDate = Inputs.text({
type: "date",
label: html`<b>A Date in the Future</b>`,
min: today,
value: today
})
Insert cell
futureDate
Insert cell
[futureDate, viewof futureDate.checkValidity()]
Insert cell
genDateRangeCheck = function(minDate, maxDate) {
// minDate and maxDate MUST be in yyyy-mm-dd format
let min = d3.utcParse("%Y-%m-%d")(minDate);
let max = d3.utcParse("%Y-%m-%d")(maxDate);
return function(form) {
let now = d3.utcParse("%Y-%m-%d")(form.value);
return now >= min && now <= max;
};
}
Insert cell
viewof mayDate = Inputs.text({
type: "date",
label: html`<b>A Date in May</b>`,
validate: genDateRangeCheck("2021-05-01", "2021-05-31"),
value: today
})
Insert cell
md`### This actually "works" but results in one the world's worst human factors interface`
Insert cell
[mayDate, viewof mayDate.checkValidity()]
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more