@@ -30,34 +30,10 @@ @implementation RCTConvert (PSPDFAnnotation)
3030 if ([annotation isKindOfClass: [PSPDFFormElement class ]]) {
3131 PSPDFFormElement *formElement = (PSPDFFormElement *)annotation;
3232 annotationDictionary[@" isRequired" ] = @(formElement.isRequired );
33- NSDictionary *formElementJSON;
34-
35- if ([formElement isKindOfClass: [PSPDFButtonFormElement class ]]) {
36- formElementJSON = [RCTConvert buttonFormElementToJSON: (PSPDFButtonFormElement *)formElement];
37- NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
38- mutableJSON[@" type" ] = @" button" ;
39- formElementJSON = [mutableJSON copy ];
40- } else if ([formElement isKindOfClass: [PSPDFChoiceFormElement class ]]) {
41- formElementJSON = [RCTConvert choiceFormElementToJSON: (PSPDFChoiceFormElement *)formElement];
42- NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
43- mutableJSON[@" type" ] = @" choice" ;
44- formElementJSON = [mutableJSON copy ];
45- } else if ([formElement isKindOfClass: [PSPDFSignatureFormElement class ]]) {
46- formElementJSON = [RCTConvert signatureFormElementToJSON: (PSPDFSignatureFormElement *)formElement];
47- NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
48- mutableJSON[@" type" ] = @" signature" ;
49- formElementJSON = [mutableJSON copy ];
50- } else if ([formElement isKindOfClass: [PSPDFTextFieldFormElement class ]]) {
51- formElementJSON = [RCTConvert textFieldFormElementToJSON: (PSPDFTextFieldFormElement *)formElement];
52- NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
53- mutableJSON[@" type" ] = @" textField" ;
54- formElementJSON = [mutableJSON copy ];
55- } else {
56- // Skip unknown form element types
57- continue ;
33+ NSDictionary *formElementJSON = [RCTConvert formElementToJSON: formElement];
34+ if (formElementJSON != nil ) {
35+ annotationDictionary[@" formElement" ] = formElementJSON;
5836 }
59-
60- annotationDictionary[@" formElement" ] = formElementJSON;
6137 }
6238
6339 if (annotationDictionary) {
@@ -72,6 +48,36 @@ @implementation RCTConvert (PSPDFAnnotation)
7248 return [annotationsJSON copy ];
7349}
7450
51+ + (NSDictionary *)formElementToJSON : (PSPDFFormElement *)formElement {
52+ NSDictionary *formElementJSON;
53+
54+ if ([formElement isKindOfClass: [PSPDFButtonFormElement class ]]) {
55+ formElementJSON = [RCTConvert buttonFormElementToJSON: (PSPDFButtonFormElement *)formElement];
56+ NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
57+ mutableJSON[@" type" ] = @" button" ;
58+ formElementJSON = [mutableJSON copy ];
59+ } else if ([formElement isKindOfClass: [PSPDFChoiceFormElement class ]]) {
60+ formElementJSON = [RCTConvert choiceFormElementToJSON: (PSPDFChoiceFormElement *)formElement];
61+ NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
62+ mutableJSON[@" type" ] = @" choice" ;
63+ formElementJSON = [mutableJSON copy ];
64+ } else if ([formElement isKindOfClass: [PSPDFSignatureFormElement class ]]) {
65+ formElementJSON = [RCTConvert signatureFormElementToJSON: (PSPDFSignatureFormElement *)formElement];
66+ NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
67+ mutableJSON[@" type" ] = @" signature" ;
68+ formElementJSON = [mutableJSON copy ];
69+ } else if ([formElement isKindOfClass: [PSPDFTextFieldFormElement class ]]) {
70+ formElementJSON = [RCTConvert textFieldFormElementToJSON: (PSPDFTextFieldFormElement *)formElement];
71+ NSMutableDictionary *mutableJSON = [formElementJSON mutableCopy ];
72+ mutableJSON[@" type" ] = @" textField" ;
73+ formElementJSON = [mutableJSON copy ];
74+ } else {
75+ return nil ; // Return nil if no conditions match
76+ }
77+
78+ return formElementJSON;
79+ }
80+
7581+ (NSDictionary *)instantJSONFromFormElement : (PSPDFFormElement *)formElement error : (NSError **)error {
7682 NSMutableDictionary *formElementJSON = [NSMutableDictionary new ];
7783
@@ -83,6 +89,16 @@ + (NSDictionary *)instantJSONFromFormElement:(PSPDFFormElement *)formElement err
8389 if (formElementData) {
8490 NSMutableDictionary *formElementDictionary = [[NSJSONSerialization JSONObjectWithData: formElementData options: kNilOptions error: error] mutableCopy ];
8591 [formElementJSON addEntriesFromDictionary: additionalInfo];
92+
93+ // If this is a Widget annotation, add the FormElement
94+ if ([formElement isKindOfClass: [PSPDFFormElement class ]]) {
95+ formElementDictionary[@" isRequired" ] = @(formElement.isRequired );
96+ NSDictionary *formElementJSON = [RCTConvert formElementToJSON: formElement];
97+ if (formElementJSON != nil ) {
98+ formElementDictionary[@" formElement" ] = formElementJSON;
99+ }
100+ }
101+
86102 if (formElementDictionary) {
87103 [formElementJSON addEntriesFromDictionary: formElementDictionary];
88104 }
0 commit comments