@@ -98,6 +98,45 @@ export const sendValue = (fieldId, valueToSet, fieldIndex = -1) => {
98
98
}
99
99
}
100
100
} ;
101
+
102
+
103
+ function compareField ( field1 , field2 ) {
104
+ // First check if either field is null/undefined
105
+ if ( ! field1 || ! field2 ) {
106
+ return field1 === field2 ; // true only if both are null/undefined
107
+ }
108
+
109
+ // Array of properties to compare
110
+ const properties = [ 'id' , 'type' , 'label' , 'value' , 'nLines' ] ;
111
+
112
+ // Check each property
113
+ for ( const prop of properties ) {
114
+ // Handle cases where the property might not exist
115
+ const value1 = field1 [ prop ] ;
116
+ const value2 = field2 [ prop ] ;
117
+
118
+ if ( value1 !== value2 ) {
119
+ return false ;
120
+ }
121
+ }
122
+
123
+ return true ; // All properties match
124
+ }
125
+ //compare two arrays of fields
126
+ function compareFields ( fields1 , fields2 ) {
127
+ if ( fields1 . length !== fields2 . length ) {
128
+ return false ;
129
+ }
130
+ for ( let i = 0 ; i < fields1 . length ; i ++ ) {
131
+ if ( ! compareField ( fields1 [ i ] , fields2 [ i ] ) ) {
132
+ return false ;
133
+ }
134
+ }
135
+ return true ;
136
+ }
137
+
138
+
139
+
101
140
export const isValidInitData = initData => initData && initData . form && initData . form . fields && initData . form . fields . length ;
102
141
103
142
const buildMessageHandlersForInitData = ( initData , notify ) => {
@@ -113,7 +152,7 @@ const buildMessageHandlersForInitData = (initData, notify) => {
113
152
fields . push ( field ) ;
114
153
values . push ( f . value ) ;
115
154
const s = ( value ) => {
116
- if ( mobileData . fields !== fields ) {
155
+ if ( ! compareFields ( mobileData . fields , fields ) ) {
117
156
console . error ( " set-field-discarded-fields-replaced " ) ;
118
157
return ;
119
158
}
@@ -146,6 +185,7 @@ const buildMessageHandlersForInitData = (initData, notify) => {
146
185
console . error ( ' on-input-message-discarded-not-connected ' ) ;
147
186
return ;
148
187
}
188
+
149
189
if ( mobileData . fields !== fields ) {
150
190
console . error ( ' on-input-message-discarded-fields-replaced ' ) ;
151
191
return ;
0 commit comments