Skip to content

Commit

Permalink
fix: port radio widgets to design-react-kit (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
tensor5 authored Dec 22, 2023
1 parent 43bd453 commit ce093da
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions src/app/form/widgets/ChoiceExpandedWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import classNames from "classnames";
import Info from "../../components/Info";
import { useController, useFormContext } from "react-hook-form";
import { get } from "lodash";
import { FormGroup, Input, Label } from "design-react-kit";

const zipObject = (props, values) =>
props.reduce(
Expand Down Expand Up @@ -29,28 +30,30 @@ const ChoiceExpandedWidget = (props) => {
const selectOptions = zipObject(options, optionNames);
return (
<div className={className}>
<label className="control-label" htmlFor={id}>
{props.label} {props.required ? "*" : ""}
</label>
{Object.entries(selectOptions).map(([value, name]) => (
<div className="form-check" key={value}>
<input
{...inputProps}
id={`${name}-${value}`}
className="form-check-input"
type="radio"
name={name}
value={value}
checked={inputProps.value === value}
disabled={props.schema.disabled}
onChange={(e) => inputProps.onChange(e)}
ref={ref}
/>
<label className="form-check-label" htmlFor={`${name}-${value}`}>
{name}
</label>
</div>
))}
<fieldset>
<legend className="control-label" htmlFor={id}>
{props.label} {props.required ? "*" : ""}
</legend>
{Object.entries(selectOptions).map(([value, name]) => (
<FormGroup check key={value}>
<Input
{...inputProps}
id={`${name}-${value}`}
className="form-check-input"
type="radio"
name={name}
value={value}
checked={inputProps.value === value}
disabled={props.schema.disabled}
onChange={(e) => inputProps.onChange(e)}
ref={ref}
/>
<Label check htmlFor={`${name}-${value}`}>
{name}
</Label>
</FormGroup>
))}
</fieldset>

{invalid && (
<span className="help-block">
Expand Down

0 comments on commit ce093da

Please sign in to comment.