2018-04-03 22:27:41 -04:00
|
|
|
import {
|
|
|
|
Col,
|
2020-04-10 11:30:26 -04:00
|
|
|
FormFeedback,
|
2018-04-03 22:27:41 -04:00
|
|
|
FormGroup,
|
2020-04-10 11:30:26 -04:00
|
|
|
FormText,
|
2018-04-03 22:27:41 -04:00
|
|
|
Input,
|
2020-04-10 11:30:26 -04:00
|
|
|
InputGroup,
|
2018-04-03 22:27:41 -04:00
|
|
|
Label,
|
2018-05-03 15:23:48 -04:00
|
|
|
} from '//components/Bootstrap';
|
2018-04-03 22:27:41 -04:00
|
|
|
|
|
|
|
export const FormBlock = ({
|
|
|
|
children,
|
2020-04-10 11:30:26 -04:00
|
|
|
grouped = false,
|
|
|
|
helpText = null,
|
|
|
|
invalidText = null,
|
2018-04-03 22:27:41 -04:00
|
|
|
label,
|
2018-04-04 11:21:38 -04:00
|
|
|
type = 'text',
|
2020-04-10 11:30:26 -04:00
|
|
|
validText = null,
|
2018-04-03 22:27:41 -04:00
|
|
|
...props
|
|
|
|
}) => {
|
2020-04-10 11:30:26 -04:00
|
|
|
let formElement = (children !== undefined)
|
2018-04-03 22:27:41 -04:00
|
|
|
? children
|
2018-04-04 11:21:38 -04:00
|
|
|
: <Input id={props.name} name={props.name} type={type} {...props} />;
|
2018-04-03 22:27:41 -04:00
|
|
|
|
2020-04-10 11:30:26 -04:00
|
|
|
if (grouped !== false) {
|
|
|
|
formElement = <InputGroup>{formElement}</InputGroup>
|
|
|
|
}
|
|
|
|
|
|
|
|
const helperText = (helpText !== null)
|
|
|
|
? <FormText>{helpText}</FormText>
|
|
|
|
: null;
|
|
|
|
|
|
|
|
let feedbackText = invalidText
|
|
|
|
if (feedbackText === null && props.required === true) {
|
|
|
|
feedbackText = 'This field is required.';
|
|
|
|
}
|
|
|
|
|
|
|
|
const feedback = (feedbackText !== null)
|
|
|
|
? <FormFeedback>{feedbackText}</FormFeedback>
|
|
|
|
: null;
|
|
|
|
|
2018-04-03 22:27:41 -04:00
|
|
|
return (
|
2020-04-10 11:30:26 -04:00
|
|
|
<Col xs={12} md={6} xl={4} className="d-flex align-items-baseline">
|
2018-04-03 22:27:41 -04:00
|
|
|
<FormGroup>
|
2018-04-04 11:21:38 -04:00
|
|
|
<Label for={props.name}>{label}</Label>
|
2018-04-03 22:27:41 -04:00
|
|
|
{formElement}
|
2020-04-10 11:30:26 -04:00
|
|
|
{helperText}
|
|
|
|
{feedback}
|
2018-04-03 22:27:41 -04:00
|
|
|
</FormGroup>
|
|
|
|
</Col>
|
|
|
|
);
|
|
|
|
};
|