Default value on Field #1073
Answered
by
Ambushfall
felipeRmBr
asked this question in
Q&A
-
Does anyone know if there is a way to set a default value for a Field?? For example, let's say one of my fields is 'title', is there a way to set a default value for this title? somehting like
|
Beta Was this translation helpful? Give feedback.
Answered by
Ambushfall
Jan 29, 2023
Replies: 1 comment 2 replies
-
Hello, the prop you're looking for is value. Suggested Solution:let [title] = await fields([
{
name: "title",
label: "Title",
type: "text",
placeholder: "John",
value: "My default title" // using the pre-set prop value satisfies your request
}
]) Types and Interface for the fields methodexport interface Fields {
(fields: string[] | Field[]): Promise<any>
(
config: PromptConfig & { fields: string[] | Field[] }
): Promise<any>
}
type Field = {
label?: string
placeholder?: string
value?: string
type?: string
[key: string]: string
}
export type PromptConfig = {
validate?: (
choice: string
) => boolean | string | Promise<boolean | string>
choices?: Choices<any> | Panel
html?: string
formData?: any
fields?: string[]
className?: string
flags?: FlagsOptions
preview?: string | (() => string | Promise<string>)
panel?: string | (() => string | Promise<string>)
onNoChoices?: ChannelHandler
onEscape?: ChannelHandler
onAbandon?: ChannelHandler
onBack?: ChannelHandler
onForward?: ChannelHandler
onUp?: ChannelHandler
onDown?: ChannelHandler
onLeft?: ChannelHandler
onRight?: ChannelHandler
onTab?: ChannelHandler
onInput?: ChannelHandler
onChange?: ChannelHandler
onBlur?: ChannelHandler
onChoiceFocus?: ChannelHandler
onPaste?: ChannelHandler
onDrop?: ChannelHandler
debounceInput?: number
debounceChoiceFocus?: number
onInputSubmit?: {
[key: string]: any
}
env?: any
shortcuts?: Shortcut[]
} & Partial<Omit<PromptData, "choices" | "id" | "script">> |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
felipeRmBr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello, the prop you're looking for is value.
Suggested Solution:
Types and Interface for the fields method