Skip to content

Commit

Permalink
refactor(component): Pass in the entire field meta and have the compo…
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Nov 11, 2024
1 parent 2684ad7 commit 619ceda
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
12 changes: 4 additions & 8 deletions src/components/form/Select.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@

const Select = ({
id,
choices = [],
label,
helptext=null,
required=false,
error_text=null,
value = '',
onChange = null,
Expand All @@ -22,16 +18,16 @@ const Select = ({

return (
<fieldset>
<label className="name" for={id}>{label}</label>
<label className="name" for={id}>{field_data.label}</label>
<select
id={id}
required={required}
required={field_data.required}
className="common-field"
onChange={onChange}
multiple = {field_data.relationship_type == 'ManyToMany' ? true : false}
>
<option value="">Please select an option</option>
{choices.map((choice) => {
{field_data.choices.map((choice) => {

let selected = false

Expand All @@ -54,7 +50,7 @@ const Select = ({

})}
</select>
<span className="help-text">{helptext}</span>
<span className="help-text">{field_data.help_text}</span>
<span className="error-text">{error_text}</span>
</fieldset>
);
Expand Down
4 changes: 0 additions & 4 deletions src/layout/ModelForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,8 @@ const ModelForm = ({
case 'Relationship':

return (<Select
choices={metadata.fields[field_key].choices}
id = {field_key}
label = {metadata.fields[field_key].label}
helptext = {metadata.fields[field_key].help_text}
error_text = {form_error && form_error[field_key]}
required = {metadata.fields[field_key].required}
value={value}
onChange={handleChange}
field_data={metadata.fields[field_key]}
Expand Down

0 comments on commit 619ceda

Please sign in to comment.