From 6a4946862fdd63fb2786fb0f5f94dc6f784930ce Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 13 Nov 2024 17:07:55 +0930 Subject: [PATCH] refactor(component): Pass field object directly to textarea 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 --- src/components/form/Textarea.jsx | 48 ++++++++++++++++++++++++++++---- src/layout/ModelForm.jsx | 12 ++------ 2 files changed, 46 insertions(+), 14 deletions(-) diff --git a/src/components/form/Textarea.jsx b/src/components/form/Textarea.jsx index d732072..ad65f0f 100644 --- a/src/components/form/Textarea.jsx +++ b/src/components/form/Textarea.jsx @@ -1,18 +1,56 @@ 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 (
@@ -20,7 +58,7 @@ const TextArea = ({