Skip to content

Commit 7862f28

Browse files
Merge pull request #46 from DSACMS/sachin/mergeFieldsFix
Fixed Merging Bug of Fields
2 parents 4641d8c + 097e202 commit 7862f28

File tree

3 files changed

+41
-32
lines changed

3 files changed

+41
-32
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_Store

index.html

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<!-- <script src="https://cdn.form.io/formiojs/formio.full.js"></script> -->
1515
<!-- <script src="https://cdn.form.io/js/formio.embed.js"></script> -->
1616

17+
<link rel="icon" type="image/x-icon" href="favicon.ico">
18+
1719
<!-- Uses bootstrap for now -->
1820
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
1921
<link rel="stylesheet" href="css/styles.css">

js/autoGenerateFields.js

+38-32
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// We wait for DOM to be fully loaded before initializing
21
document.addEventListener("DOMContentLoaded", function() {
32
setupFormHandler();
43
setupNotificationSystem();
@@ -158,6 +157,20 @@ function preFillFields(repoData, languages) {
158157
}
159158

160159
try {
160+
const currentSubmission = {}
161+
162+
window.formIOInstance.components.forEach(component => {
163+
if (component.components) {
164+
component.components.forEach(nestedComp => {
165+
if (nestedComp.key) {
166+
currentSubmission[nestedComp.key] = nestedComp.getValue()
167+
}
168+
});
169+
} else if (component.key) {
170+
currentSubmission[component.key] = component.getValue()
171+
}
172+
})
173+
161174
let licenses = [];
162175
if (repoData.license && repoData.license.spdx_id) {
163176
licenses.push({
@@ -166,38 +179,31 @@ function preFillFields(repoData, languages) {
166179
});
167180
}
168181

169-
const submission = {
170-
data: {
171-
name: repoData.name || '',
172-
description: repoData.description || '',
173-
174-
repositoryURL: repoData.html_url || '',
175-
repositoryVisibility: repoData.private ? "private" : "public",
176-
vcs: 'git',
177-
178-
permissions: {
179-
licenses: licenses
180-
},
181-
182-
reuseFrequency: {
183-
forks: repoData.forks_count || 0
184-
},
185-
186-
languages: Object.keys(languages) || [],
187-
188-
date: {
189-
created: repoData.created_at || '',
190-
lastModified: repoData.updated_at || '',
191-
metaDataLastUpdated: new Date().toISOString()
192-
},
193-
194-
tags: repoData.topics || [],
195-
196-
feedbackMechanisms: [repoData.html_url + "/issues"]
197-
}
198-
};
182+
const newSubmission = {
183+
name: repoData.name || '',
184+
description: repoData.description || '',
185+
repositoryURL: repoData.html_url || '',
186+
repositoryVisibility: repoData.private ? "private" : "public",
187+
vcs: 'git',
188+
permissions: {
189+
licenses: licenses
190+
},
191+
reuseFrequency: {
192+
forks: repoData.forks_count || 0
193+
},
194+
languages: Object.keys(languages) || [],
195+
date: {
196+
created: repoData.created_at || '',
197+
lastModified: repoData.updated_at || '',
198+
metaDataLastUpdated: new Date().toISOString()
199+
},
200+
tags: repoData.topics || [],
201+
feedbackMechanisms: [repoData.html_url + "/issues"]
202+
}
199203

200-
window.formIOInstance.setSubmission(submission);
204+
const mergedSubmission = { ...currentSubmission, ...newSubmission}
205+
206+
window.formIOInstance.setSubmission({ data: mergedSubmission })
201207

202208
} catch (error) {
203209
notificationSystem.error("Error filling form fields with repository data. Please refresh and try again");

0 commit comments

Comments
 (0)