components.form.fields.InputRadioField.js Maven / Gradle / Ivy
import _ from "lodash";
import {
FormControl,
FormLabel,
RadioGroup,
FormControlLabel,
Radio,
FormHelperText,
Box } from "@mui/material";
import { formatChoices } from "components/form/utils/input-utils";
import { getEventValue, validateField } from "components/form/utils/validate-utils";
import { useFieldInfo } from "hooks/field";
import { isOption } from "utils/option-utils";
import { useTranslator } from "hooks/translator";
import { useFormInfo } from "hooks/form";
import { useAutoSubmitSignal } from "hooks/autosubmit";
const InputRadioField = () => {
const { fieldProps, info, augProps } = useFieldInfo()
const formInfo = useFormInfo()
const { translator } = useTranslator()
const { signal } = useAutoSubmitSignal()
const options = formatChoices(translator, info.options, info.optionsKind, formInfo.processDefinition.key)
const booleanMode = info.type === "RADIO BOOLEAN SELECT"
const currentValue = isOption(fieldProps.value) ? fieldProps.value.value : fieldProps.value
function handleChange(e) {
augProps.setRuntimeError(null)
const value = getOptionValue(e)
augProps.setValue(value)
validate(e, value)
}
function getOptionValue(e) {
const value = getEventValue(e, null)
// in boolean mode only return true/false, otherwise { key, value }
return booleanMode ? value : getOptionByValue(value)
}
function getOptionByValue(value) {
return options.find(option => option.value === value)
}
function handleBlur(e) {
fieldProps.onBlur(e)
validate(e, fieldProps.value)
signal()
}
function validate(e, value) {
augProps.setError(validateField("radio", fieldProps.required, e, value))
}
return (
<>
{ !info.inMultiple ? : null }
{!info.inMultiple ? {fieldProps.label} : null}
{fieldProps.helperText}
>
);
}
const RadioOptions = ({ options, onChange }) => {
return options.map((option, index) =>
}
/>
)
}
export default InputRadioField