The Form
component should wrap FieldGroup
components to apply consistent layouts. All the fields are controlled inputs, so you need to provide both value
and onChange
props to make it work.
The onChange
prop of all field components always returns the new value as first parameter, so you don't need to inspect the event
object to get it.
<Canvas ctx={ctx}><Form onSubmit={() => console.log('onSubmit')}><FieldGroup><TextFieldrequiredname="name"id="name"label="Name"value="Mark Smith"placeholder="Enter full name"hint="Provide a full name"onChange={(newValue) => console.log(newValue)}/><TextFieldrequiredname="email"id="email"label="Email"type="email"value=""placeholder="your@email.com"error="Please enter an email!"hint="Enter email address"onChange={(newValue) => console.log(newValue)}/><TextFieldrequiredname="apiToken"id="apiToken"label="API Token"value="XXXYYY123"hint="Enter a valid API token"textInputProps={{ monospaced: true }}onChange={(newValue) => console.log(newValue)}/><SelectFieldname="option"id="option"label="Option"hint="Select one of the options"value={{ label: 'Option 1', value: 'option1' }}selectInputProps={{options: [{ label: 'Option 1', value: 'option1' },{ label: 'Option 2', value: 'option2' },{ label: 'Option 3', value: 'option3' },],}}onChange={(newValue) => console.log(newValue)}/><SelectFieldname="multipleOption"id="multipleOption"label="Multiple options"hint="Select one of the options"value={[{ label: 'Option 1', value: 'option1' },{ label: 'Option 2', value: 'option2' },]}selectInputProps={{isMulti: true,options: [{ label: 'Option 1', value: 'option1' },{ label: 'Option 2', value: 'option2' },{ label: 'Option 3', value: 'option3' },],}}onChange={(newValue) => console.log(newValue)}/><SwitchFieldname="debugMode"id="debugMode"label="Debug mode active?"hint="Logs messages to console"value={true}onChange={(newValue) => console.log(newValue)}/></FieldGroup><FieldGroup><Button fullWidth buttonType="primary">Submit</Button></FieldGroup></Form></Canvas>