Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle array inputs in iframe-field-modal #2491

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/components/modals/iframe-field-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,18 @@ const IframeFieldModal = ({
filesize: colData.size
};

}
else if (col.type?.isArray) {
try {
// the iframe will send the array value in a string, so we have to turn it into a proper array
const arrayValue = JSON.parse(colData);
if (Array.isArray(arrayValue)) {
// mimic the same structure that we have in array fields (the value is stored inside the .val prop)
values[`c_${formNumber}-${col.RID}`] = arrayValue.map((v: any) => ({val: v}));
}
} catch (exp) {
values[`c_${formNumber}-${col.RID}`] = [];
}
} else {
values[`c_${formNumber}-${col.RID}`] = colData;
}
Expand Down
8 changes: 7 additions & 1 deletion test/e2e/data_setup/schema/recordedit/input-iframe.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,13 @@
{
"name": "notes",
"nullok": true,
"type": {"typename": "text"}
"type": {
"is_array": true,
"typename": "text[]",
"base_type": {
"typename": "text"
}
}
}
],
"annotations": {
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/specs/all-features/recordedit/input-iframe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ const testParams = {
secondAttemptValues: {
creator: 'John Smith II',
file_content: 'actually the content should be this one.',
notes: 'some notes'
notes: '["note 1","note 2"]'
},
submission: {
tableDisplayname: 'main',
resultColumnNames: ['id', 'creator', 'notes'],
resultRowValues: [['1', 'John Smith II', 'some notes']]
resultRowValues: [['1', 'John Smith II', 'note 1, note 2']]
}
},
edit: {
Expand All @@ -46,7 +46,7 @@ const testParams = {
existingValues: {
creator: 'John Smith II',
file_content: 'actually the content should be this one.',
notes: 'some notes'
notes: '["note 1","note 2"]'
},
newValues: {
creator: 'Kylan Gentry',
Expand Down
7 changes: 5 additions & 2 deletions test/e2e/utils/input-iframe-test.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
const fetchExistingData = (existingValue) => {
const fileURL = existingValue[FIELD_NAMES.FILE];
const creator = existingValue[FIELD_NAMES.CREATOR];
const notes = existingValue[FIELD_NAMES.NOTES];
let notes = existingValue[FIELD_NAMES.NOTES];
if (Array.isArray(notes)) {
notes = JSON.stringify(notes);
}

fetch(fileURL).then(response => {
if (response.ok) {
Expand Down Expand Up @@ -138,7 +141,7 @@ <h1>Sample iframe used by <code>input_iframe</code></h1>
<br/>
<label for="file-content">File content:</label><br/><textarea id="file-content" name="file-content" rows="4" cols="50"></textarea>
<br/>
<label for="notes">Notes:</label><br/><input type="text" id="notes" name="notes">
<label for="notes">Notes (array of text):</label><br/><input type="text" id="notes" name="notes">
<br/>
<button id='iframe-submit-btn' type="button" onclick="submitData()">submit</button>
</div>
Expand Down
Loading