You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prompts chain of Start/End dates, End date should not be before Start date.
constresponses=awaitprompts([{type: 'date',name: 'startDate',message: 'Start Date',initial: newDate(),},{type: 'date',name: 'endDate',message: 'End Date',initial: newDate(),validate(date){// `endDate` should not be before `startDate`},},]);
Solution
{type: 'date',name: 'endDate',message: 'End Date',initial: newDate(),validate(date,values){returndate>=values.startDate||'End Date should not be before Start Date';},},
Describe alternatives you've considered
Multiple prompts or onSubmit hacks as mentioned in #2.
If we already have validate, makes sense to allow access to previous answers.
I was also thinking about min and max values that could make sense (additionally)...
e.g. Once startDate is selected, endDate could have min: (prev, values) => values.startDate and then the user can't select a date before that date.
Additional context
Maybe it makes sense, for consistency, to add prompt as the 3rd argument, just like some of the other props https://github.com/terkelg/prompts#-prompt-objects. Though I'm not sure what would be the use case for that.
Btw, format doesn't get prompt as a 3rd argument but the docs in the same section say:
The function signature is (prev, values, prompt)
The text was updated successfully, but these errors were encountered:
I just wanted to confirm that I really badly need this too. I tried to look into the code, and got a little lost (although I am drowning in my own code right now)
My solution (hopefully temporary, to be fixed once this issue is addressed) was to do this:
let globalPrev
const questions = [
{
type: 'select',
name: 'destination',
message: 'Destination element',
choices: anchorPoints()
},
{
type: 'text',
name: 'subPath',
message: (prev) => { globalPrev = prev; return `Nested URL, nested in ${prev}` },
validate: (value) => {
// The actual validator will have access to 'prev'
return utils.pagePathValidator(config, value, globalPrev)
}
}
]
I too need this badly - I took a stab at it and have tested it on my current project. Please provide some feedback as I'd love to get this in (see auto-linked message above).
Problem
Prompts chain of Start/End dates, End date should not be before Start date.
Solution
Describe alternatives you've considered
Multiple prompts or
onSubmit
hacks as mentioned in #2.If we already have
validate
, makes sense to allow access to previous answers.I was also thinking about
min
andmax
values that could make sense (additionally)...e.g. Once
startDate
is selected,endDate
could havemin: (prev, values) => values.startDate
and then the user can't select a date before that date.Additional context
Maybe it makes sense, for consistency, to add
prompt
as the 3rd argument, just like some of the other props https://github.com/terkelg/prompts#-prompt-objects. Though I'm not sure what would be the use case for that.Btw,
format
doesn't getprompt
as a 3rd argument but the docs in the same section say:The text was updated successfully, but these errors were encountered: