@@ -14,14 +14,26 @@ const formatName = (name, textFormat = 'lowercase') => {
14
14
} ;
15
15
16
16
/**
17
- * Handles the formatting logic for field values.
18
- * For the "organization" field ID, it retains hyphens in the selected value but displays without hyphens in uppercase.
17
+ * Defines the rules for formatting the field value based on the field id.
18
+ * Removes hyphens and formats in uppercase for display
19
+ * Retains hyphens in the stored value
19
20
*/
21
+ const FIELD_FORMAT_RULES = {
22
+ organization : {
23
+ display : ( value ) => formatName ( value . replace ( / [ _ - ] / g, ' ' ) , 'uppercase' ) ,
24
+ store : ( value ) => value ,
25
+ } ,
26
+ default : {
27
+ display : ( value , textFormat ) => formatName ( value , textFormat ) ,
28
+ store : ( value , textFormat ) => formatName ( value , textFormat ) ,
29
+ } ,
30
+ } ;
31
+
20
32
const formatFieldValue = ( value , fieldId , textFormat , display = false ) => {
21
- if ( fieldId === 'organization' ) {
22
- return display ? formatName ( value , 'uppercase' ) : value ;
23
- }
24
- return formatName ( value , textFormat ) ;
33
+ const rules = FIELD_FORMAT_RULES [ fieldId ] || FIELD_FORMAT_RULES . default ;
34
+ return display
35
+ ? rules . display ( value , textFormat )
36
+ : rules . store ( value , textFormat ) ;
25
37
} ;
26
38
27
39
/**
0 commit comments