Skip to content

Commit 649cd57

Browse files
committed
compre-fields-deep
1 parent c54d645 commit 649cd57

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

src/globalinput.js

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,45 @@ export const sendValue = (fieldId, valueToSet, fieldIndex = -1) => {
9898
}
9999
}
100100
};
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+
101140
export const isValidInitData = initData => initData && initData.form && initData.form.fields && initData.form.fields.length;
102141

103142
const buildMessageHandlersForInitData = (initData, notify) => {
@@ -113,7 +152,7 @@ const buildMessageHandlersForInitData = (initData, notify) => {
113152
fields.push(field);
114153
values.push(f.value);
115154
const s = (value) => {
116-
if (mobileData.fields !== fields) {
155+
if(!compareFields(mobileData.fields, fields)) {
117156
console.error(" set-field-discarded-fields-replaced ");
118157
return;
119158
}
@@ -146,6 +185,7 @@ const buildMessageHandlersForInitData = (initData, notify) => {
146185
console.error(' on-input-message-discarded-not-connected ');
147186
return;
148187
}
188+
149189
if (mobileData.fields !== fields) {
150190
console.error(' on-input-message-discarded-fields-replaced ');
151191
return;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy