Skip to content

Commit

Permalink
feat(layout): On form field error, scroll to top of form
Browse files Browse the repository at this point in the history
  • Loading branch information
jon-nfc committed Nov 11, 2024
1 parent 30108ab commit 4159b2d
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions src/layout/ModelForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ const ModelForm = ({

navigate(url_builder.return_url)

} else {

window.scrollTo(0, 0)

}
}}>
{ metadata && params.action == 'delete' &&
Expand Down Expand Up @@ -221,15 +225,32 @@ const ModelForm = ({

default:

return (<TextField
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}
/>)
if( 'multi_line' in metadata.fields[field_key] ) {


return (<TextArea
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}
/>)

} else {

return (<TextField
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}
/>)

}
}


Expand Down

0 comments on commit 4159b2d

Please sign in to comment.