feat(ui): Add required indicator to form field

This commit is contained in:
Richard Palethorpe
2025-03-26 09:11:03 +00:00
parent 4dcc77372d
commit d520d88301

View File

@@ -25,6 +25,13 @@ const FormField = ({
options = [], options = [],
required = false, required = false,
}) => { }) => {
// Create label with required indicator
const labelWithIndicator = required ? (
<>{label} <span style={{ color: 'var(--danger)' }}>*</span></>
) : (
label
);
// Render different input types // Render different input types
const renderInput = () => { const renderInput = () => {
switch (type) { switch (type) {
@@ -38,7 +45,7 @@ const FormField = ({
checked={value === true || value === 'true'} checked={value === true || value === 'true'}
onChange={(e) => onChange(e.target.checked ? 'true' : 'false')} onChange={(e) => onChange(e.target.checked ? 'true' : 'false')}
/> />
{label} {labelWithIndicator}
</label> </label>
{helpText && <small className="form-text text-muted d-block">{helpText}</small>} {helpText && <small className="form-text text-muted d-block">{helpText}</small>}
</div> </div>
@@ -46,7 +53,7 @@ const FormField = ({
case 'select': case 'select':
return ( return (
<> <>
<label htmlFor={id}>{label}</label> <label htmlFor={id}>{labelWithIndicator}</label>
<select <select
id={id} id={id}
value={value || ''} value={value || ''}
@@ -66,7 +73,7 @@ const FormField = ({
case 'textarea': case 'textarea':
return ( return (
<> <>
<label htmlFor={id}>{label}</label> <label htmlFor={id}>{labelWithIndicator}</label>
<textarea <textarea
id={id} id={id}
value={value || ''} value={value || ''}
@@ -81,7 +88,7 @@ const FormField = ({
default: default:
return ( return (
<> <>
<label htmlFor={id}>{label}</label> <label htmlFor={id}>{labelWithIndicator}</label>
<input <input
type={type} type={type}
id={id} id={id}