[BUG] FormUtils.eachComponent fails iteration on component.columns
See original GitHub issueEnvironment
- Hosting type
- Form.io
- Local deployment
- Version:
- Formio.js version: 4.6.2
- Frontend framework: Angular@8.2.5
- Renderer: angular-formio@4.2.12
- Browser: chrome
- Browser version: 77.0.3865.120
Steps to Reproduce
- Inside the Form Builder
- Create a form
- Add a column component
- Add a TextField component inside the column component
- Edit the submit button and change action to custom
- Add the following code to the “Button Custom Logic”
utils.eachComponent(form.components, (component, path) => {
console.log(component.key)
}, true);
- Save component
- Save the form
- In the form manager go to the “Enter Data” section
- click submit button
Expected behavior
It should prints the keys of all components columns textField submit
Observed behavior
It doesn’t print the keys of the components that belong to a column component columns submit
Solution proposal
file: formio.js/src/utils/formUtils.js
export function eachComponent(components, fn, includeAll, path, parent) {
if (!components) return;
path = path || '';
components.forEach((component) => {
...
if (!noRecurse) {
if (hasColumns) {
component.columns.forEach((column) =>
//replacing
//eachComponent(column.components, fn, includeAll, subPath(), parent ? component : null));
//with
eachComponent(column.components || column, fn, includeAll, subPath(), parent ? component : null);
}
else if (hasRows) {
component.rows.forEach((row) => {
if (Array.isArray(row)) {
row.forEach((column) =>
//maybe also replacing (I don't know, I should check)
//eachComponent(column.components, fn, includeAll, subPath(), parent ? component : null));
//with
eachComponent(column.components || column, fn, includeAll, subPath(), parent ? component : null);
}
});
}
else if (hasComps) {
eachComponent(component.components, fn, includeAll, subPath(), parent ? component : null);
}
}
});
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
SSIS Script Component - Iterating through input columns
I'm trying to script the component to iterate through all input columns (as selected in the input columns screen) and build a simple...
Read more >SSIS foreach loop, continue but also perform an action on ...
So after some more in depth searching - it seems the answer is to simply perform error handling on every component within the...
Read more >Error Message: The Flat File Source.Outputs[Flat File ... - cozyroc
Columns [THUNK_COLUMN] has an invalid error or truncation row disposition." Solution: To avoid error message produced on second iteration of Foreach Loop follow ......
Read more >21 Iteration | R for Data Science - Hadley Wickham
Here I've used unlist() to flatten a list of vectors into a single vector. A stricter option is to use purrr::flatten_dbl() — it...
Read more >R Open Labs: Scripting 2 - Loops and Error Handling
In this case, it's the vector 1:5, so the loop is going to iterate 5 times. Our sequence also has a variable called...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@agrawalankush,
We have gotten feedback from our developer that was looking into this issue. Here is the information that they provided us with:
utils’ eachComponent method is used for iterating through JSON schemes of components which has a specific format. So, in the Columns’ JSON, each row must always be an object with the ‘components’ field. But in the Columns instance, each column is just an array of components. So, for iterating through components’ instances they should use everyComponent method of the Form’s instance/any component’s instance. E.g.: formInstance.everyComponent((componentInstance) => { // Do what you want with componentInstance return true; // In order to stop iterating just return false });
I hope that this helps.
wag11084’s comment works as a solution for my problem. For our forms we use
mm/dd/yyyy
syntax for dates since that’s what our audience is familiar with and then we format the payload of certain fields to use ISO date format when we submit to our backend. Had the same problem as teknoel whereUtils.eachComponent(form.components)
wasn’t treating components with the same condition the same way; I just hadn’t connected the dots that it was because they were in a Layout component.Thanks all for your efforts 🚀