@@ -32,84 +32,82 @@ let make = (~fieldConfig: SuperpositionTypes.fieldConfig) => {
3232
3333 let validate = DynamicFieldsUtils .resolveValidator (~field = fieldConfig , ~localeObject = localeString )
3434
35- <ReactFinalForm .Field name = {path } validate = {Some (validate )}>
36- {(field : ReactFinalForm .Field .fieldProps ) => {
37- let touched = field .meta .touched
38- let invalid = field .meta .invalid
39- <div className = "flex flex-col gap-1" >
40- <div
41- className = {` Label` }
42- style = {
43- fontWeight : themeObj .fontWeightNormal ,
44- fontSize : themeObj .fontSizeLg ,
45- opacity : "0.6" ,
46- }>
47- {label -> React .string }
35+ let field = ReactFinalForm .useField (path , ~config = {validate : validate })
36+ let touched = field .meta .touched
37+ let invalid = field .meta .invalid
38+
39+ <div className = "flex flex-col gap-1" >
40+ <div
41+ className = {` Label` }
42+ style = {
43+ fontWeight : themeObj .fontWeightNormal ,
44+ fontSize : themeObj .fontSizeLg ,
45+ opacity : "0.6" ,
46+ }>
47+ {label -> React .string }
48+ </div >
49+ <DatePicker
50+ showIcon = true
51+ icon = {<Icon name = "calander" size = 13 className = "!px-[6px] !py-[10px]" />}
52+ className = "w-full border border-gray-300 rounded p-2"
53+ selected = {selectedDate }
54+ onChange = {date => {
55+ setSelectedDate (_ => date )
56+ let strVal =
57+ date
58+ -> Nullable .toOption
59+ -> Option .map (d => d -> Date .toLocaleDateStringWithLocale ("en-CA" ))
60+ -> Option .getOr ("" )
61+ field .input .onChange (strVal )
62+ }}
63+ dateFormat
64+ wrapperClassName = "datepicker"
65+ shouldCloseOnSelect = true
66+ placeholderText = {placeholder }
67+ renderCustomHeader = {val => {
68+ <div className = "flex gap-4 items-center justify-center m-2" >
69+ <select
70+ className = "p-1"
71+ value = {val .date -> Date .getFullYear -> Int .toString }
72+ onChange = {ev => {
73+ let value = {ev -> ReactEvent .Form .target }["value" ]
74+ val .changeYear (value )
75+ }}>
76+ {years
77+ -> Array .map (option =>
78+ <option key = {option -> Int .toString } value = {option -> Int .toString }>
79+ {option -> React .int }
80+ </option >
81+ )
82+ -> React .array }
83+ </select >
84+ <select
85+ className = "p-1"
86+ value = {months [val .date -> Date .getMonth ]-> Option .getOr ("January" )}
87+ onChange = {ev => {
88+ let value = {ev -> ReactEvent .Form .target }["value" ]
89+ val .changeMonth (months -> Array .indexOf (value ))
90+ }}>
91+ {months
92+ -> Array .map (option =>
93+ <option key = {option } value = {option }> {option -> React .string } </option >
94+ )
95+ -> React .array }
96+ </select >
4897 </div >
49- <DatePicker
50- showIcon = true
51- icon = {<Icon name = "calander" size = 13 className = "!px-[6px] !py-[10px]" />}
52- className = "w-full border border-gray-300 rounded p-2"
53- selected = {selectedDate }
54- onChange = {date => {
55- setSelectedDate (_ => date )
56- let strVal =
57- date
58- -> Nullable .toOption
59- -> Option .map (d => d -> Date .toLocaleDateStringWithLocale ("en-CA" ))
60- -> Option .getOr ("" )
61- field .input .onChange (strVal )
62- }}
63- dateFormat
64- wrapperClassName = "datepicker"
65- shouldCloseOnSelect = true
66- placeholderText = {placeholder }
67- renderCustomHeader = {val => {
68- <div className = "flex gap-4 items-center justify-center m-2" >
69- <select
70- className = "p-1"
71- value = {val .date -> Date .getFullYear -> Int .toString }
72- onChange = {ev => {
73- let value = {ev -> ReactEvent .Form .target }["value" ]
74- val .changeYear (value )
75- }}>
76- {years
77- -> Array .map (option =>
78- <option key = {option -> Int .toString } value = {option -> Int .toString }>
79- {option -> React .int }
80- </option >
81- )
82- -> React .array }
83- </select >
84- <select
85- className = "p-1"
86- value = {months [val .date -> Date .getMonth ]-> Option .getOr ("January" )}
87- onChange = {ev => {
88- let value = {ev -> ReactEvent .Form .target }["value" ]
89- val .changeMonth (months -> Array .indexOf (value ))
90- }}>
91- {months
92- -> Array .map (option =>
93- <option key = {option } value = {option }> {option -> React .string } </option >
94- )
95- -> React .array }
96- </select >
97- </div >
98- }}
99- />
100- <RenderIf condition = {touched && invalid }>
101- <div
102- className = "Error pt-1"
103- style = {
104- color : themeObj .colorDangerText ,
105- fontSize : themeObj .fontSizeSm ,
106- alignSelf : "start" ,
107- textAlign : "left" ,
108- }>
109- {field .meta .error -> Option .getOr ("" )-> React .string }
110- </div >
111- </RenderIf >
98+ }}
99+ />
100+ <RenderIf condition = {touched && invalid }>
101+ <div
102+ className = "Error pt-1"
103+ style = {
104+ color : themeObj .colorDangerText ,
105+ fontSize : themeObj .fontSizeSm ,
106+ alignSelf : "start" ,
107+ textAlign : "left" ,
108+ }>
109+ {field .meta .error -> Option .getOr ("" )-> React .string }
112110 </div >
113- }}
114- </ReactFinalForm . Field >
111+ </ RenderIf >
112+ </div >
115113}
0 commit comments