SFDigitalServices / formio-sfds

The form.io theme for sf.gov
https://formio-sfds.herokuapp.com/
MIT License
15 stars 2 forks source link

Nested form patch #203

Closed shawnbot closed 3 years ago

shawnbot commented 3 years ago

I tracked down the issue that @nlsfds and @JimBrodbeck raised with nested forms not rendering properly:

The t.tk is not a function errors were a great clue. It turns out that when formiojs loads the nested form, it's not properly passing the root reference down to all of its own components. I think that it's because the createSubForm() method only sets .root on the nested form after it's been created, which prevents all of its own components from "inheriting" the evalContext options of the top-level form, which is where we define the tk() method. I tried patching the convoluted getSubOptions() method that generates the options for the sub-form thinking that setting options.root = this.root would do it, but no dice.

The fix that worked for me is a patch to the nested form component's createSubForm() method that, once the sub-form is created, recursively sets both .root and .options.root on each of the nested components. I've confirmed that this resolves the issue in a browser, but I'm having a hell of a time creating a test case that runs in our Jest suite. I also don't know if this is a legit thing to do, because it's possible that components in a nested form would expect their root to be the sub-form, in which case this patch would break them. 🙃 🤔

github-actions[bot] commented 3 years ago

Size Change: +245 B (0%)

Total Size: 88.8 kB

Filename Size Change
dist/formio-sfds.standalone.js 68.4 kB +245 B (0%)
ℹ️ View Unchanged | Filename | Size | | :--- | :---: | | `dist/formio-sfds.css` | 14 kB | | `dist/portal.js` | 6.37 kB |

compressed-size-action

shawnbot commented 3 years ago

I'm going to close this, in the hopes that we can do #207 first and/or punt on nested forms. If we do need nested forms or we're not able to move forward with phasing out Phrase soon, then we can re-open.