Skip to content

Commit

Permalink
feat: add Radio Field (redwoodjs#479)
Browse files Browse the repository at this point in the history
* Add Radio Field

* Fix eslint error

* Add documentation for RadioField
  • Loading branch information
vikotar authored Apr 29, 2020
1 parent 37afc70 commit e0cfdf7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/web/src/form/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ Redwood currently provides the following form components:
* `<Label>` is used in place of the HTML `<label>` tag and can respond to errors with different styling
* `<TextField>` is used in place of the HTML `<input type="text">` tag and can accept validation options and be styled differently in the presence of an error
* `<TextAreaField>` is used in place of the HTML `<textarea>` tag and can accept validation options and be styled differently in the presence of an error
* `<RadioField>` is used in place of the HTML `<input type="radio">` tag and can accept validation options.
The default validation for `required` is `false` for this field, To make it required, please pass the prop `validation={{ required: true }}` for all the `<RadioField>`.
* `<FieldError>` will display error messages from form validation and server errors
* `<Submit>` is used in place of `<button type="submit">` and will trigger a validation check and "submission" of the form (actually executes the function given to the `onSubmit` attribute on `<Form>`)

Expand Down
16 changes: 16 additions & 0 deletions packages/web/src/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ const TextField = (props) => {
)
}

// Renders an <input type="radio"> field
const RadioField = (props) => {
const { register } = useFormContext()
const tagProps = inputTagProps(props)

return (
<input
{...tagProps}
type="radio"
id={props.id || props.name}
ref={register(props.validation || { required: false })}
/>
)
}

// Renders a <select> field

const SelectField = (props) => {
Expand Down Expand Up @@ -240,6 +255,7 @@ export {
HiddenField,
TextAreaField,
TextField,
RadioField,
SelectField,
Submit,
}

0 comments on commit e0cfdf7

Please sign in to comment.