Skip to content

Basic date range input #1366

Closed Answered by ae3e
ae3e asked this question in Q&A
May 17, 2024 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

I finally solved my problem by writing code in the reduce function of the button.

Here is the component file :

import {button, datetime, form} from "npm:@observablehq/inputs";

let startInput = datetime({ label: "From", value: new Date()-7*24*3600000});
let endInput = datetime({ label: "To", value: new Date(),validate:e=>new Date(e.value)>startInput.value });

const predefinedPeriodInput = button([
  ["6 hours", value => setRange(6*3600*1000)],
  ["2 days", value => setRange(2*24*3600*1000)],
  ["1 week", value => setRange(7*24*3600*1000)],
  ["1 month", value => setRange(31*24*3600*1000)],
  ["1 year", value => setRange(365*24*3600*1000)]
], {value: null, width:90});

const setRange = (p…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryanmckaytx
Comment options

Answer selected by ae3e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants