Skip to content

Commit

Permalink
refactor(component): Pass field object directly to textarea
Browse files Browse the repository at this point in the history
pasing the whole object as the component is to do ALL logic for the field

ref: #26 #27 nofusscomputing/centurion_erp#248 nofusscomputing/centurion_erp#388
  • Loading branch information
jon-nfc committed Nov 13, 2024
1 parent a8b86c6 commit 6a49468
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
48 changes: 43 additions & 5 deletions src/components/form/Textarea.jsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,64 @@
const TextArea = ({
id,
label,
helptext=null,
required=false,
error_text=null,
value= '',
onChange = null,
class_name = null
class_name = null,
field_data = null
}) => {

if( value === null ) {
value = ''
}

let field_class_name = "common-field"
let helptext = null
let required = false
let label = ''

if( field_data ) {

field_data = Object(field_data)



if( 'help_text' in field_data) {

helptext = field_data['help_text']

}

if( 'label' in field_data ) {

label = field_data['label']

}

if( 'required' in field_data) {

required = field_data['required']

}

if( 'style' in field_data ) {

if( 'class' in field_data.style ) {

field_class_name += String( ' ' + field_data['style']['class'])

}
}
}


return (
<fieldset className={class_name}>
<label className="name" for={id}>{label}</label>
<span className="help-text">{helptext}</span>
<textarea
id={id}
required={required}
className="common-field"
className={field_class_name}
onChange={onChange}
onKeyUp={(e) =>{

Expand Down
12 changes: 3 additions & 9 deletions src/layout/ModelForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,8 @@ const ModelForm = ({

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}
field_data={metadata.fields[field_key]}
value={value}
onChange={handleChange}
/>)
Expand All @@ -267,10 +265,8 @@ const ModelForm = ({

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}
field_data={metadata.fields[field_key]}
value={value}
onChange={handleChange}
/>)
Expand All @@ -282,10 +278,8 @@ const ModelForm = ({

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}
field_data={metadata.fields[field_key]}
value={value}
onChange={handleChange}
/>)
Expand Down

0 comments on commit 6a49468

Please sign in to comment.