question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] FormUtils.eachComponent fails iteration on component.columns

See original GitHub issue

Environment

  • 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

  1. Inside the Form Builder
  2. Create a form
  3. Add a column component
  4. Add a TextField component inside the column component
  5. Edit the submit button and change action to custom
  6. Add the following code to the “Button Custom Logic”
  utils.eachComponent(form.components, (component, path) => {
    console.log(component.key)
  }, true);
  1. Save component
  2. Save the form
  3. In the form manager go to the “Enter Data” section
  4. 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:closed
  • Created 4 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wag110894commented, Aug 25, 2020

@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.

0reactions
SalTorcommented, Aug 31, 2020

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 where Utils.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 🚀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found