Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6752 from guardian/revert-6746-revert-6722-tom-ki…
…ng-form-fields-refactor Revert "Revert "Add validation errors to form fields for callouts""
- Loading branch information
Showing
9 changed files
with
96 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,37 @@ | ||
import { CampaignFieldSelect } from '../../../types/content'; | ||
import { FieldLabel } from './FieldLabel'; | ||
import { Select as SourceSelect } from '@guardian/source-react-components'; | ||
import type { CampaignFieldSelect } from 'src/types/content'; | ||
|
||
type Props = { | ||
validationErrors?: { [key in string]: string }; | ||
formField: CampaignFieldSelect; | ||
formData: { [key in string]: any }; | ||
setFormData: React.Dispatch<React.SetStateAction<{ [x: string]: any }>>; | ||
}; | ||
|
||
export const Select = ({ formField, formData, setFormData }: Props) => ( | ||
<> | ||
<FieldLabel formField={formField} /> | ||
<select | ||
data-testid={`form-field-${formField.id}`} | ||
required={formField.required} | ||
value={ | ||
formField.id && formField.id in formData | ||
? formData[formField.id] | ||
: '' | ||
} | ||
onChange={(e) => | ||
setFormData({ | ||
...formData, | ||
[formField.id]: e.target.value, | ||
}) | ||
} | ||
> | ||
{formField.options && | ||
formField.options.map((option, index) => ( | ||
<option key={index} value={option.value}> | ||
{option.value} | ||
</option> | ||
))} | ||
</select> | ||
</> | ||
export const Select = ({ | ||
validationErrors, | ||
formField, | ||
formData, | ||
setFormData, | ||
}: Props) => ( | ||
<SourceSelect | ||
hideLabel={formField.hideLabel} | ||
data-testid={`form-field-${formField.id}`} | ||
error={validationErrors?.[formField.id]} | ||
label={formField.label} | ||
supporting={formField.description} | ||
value={formField.id in formData ? formData[formField.id] : ''} | ||
onChange={(e) => | ||
setFormData({ | ||
...formData, | ||
[formField.id]: e.target.value, | ||
}) | ||
} | ||
optional={!formField.required} | ||
children={formField.options.map((option, index) => ( | ||
<option key={index} value={option.value}> | ||
{option.value} | ||
</option> | ||
))} | ||
/> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters