Last active
May 27, 2021 15:13
-
-
Save avwilks/fa6a6a96c89a6fa535660b4112af1236 to your computer and use it in GitHub Desktop.
Conditional Fields Example Document
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"field1":{ | |
"field1a":{ | |
"when":"(a) => a.includes('USA')" | |
}, | |
"field1b":{ | |
"when":"(a) => a.includes('Mexico')" | |
}, | |
"field1c":{ | |
"when":"(a) => a.includes('Canada')", | |
"field1ca": { | |
"when": "(a) => a.includes('Ontario')", | |
"field1caa": { | |
"when": "(a) => a.length > 0" | |
} | |
} | |
} | |
}, | |
"field2":{ | |
"field2a": { | |
"when":"(a) => a === 'Yes'" | |
} | |
} | |
} |
Where do we store the show condition in this concept? With the rest of the metadata?
The "show condition" is implied with this method. As we visit each node - and whatever AND/OR nodes are associated with it - we render the field in the DOM
a quick example of how I imagine node traversal working with this: https://codesandbox.io/s/staging-darkness-15r62?file=/src/App.js
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Maybe we can revise this to be something like (pretty much a trie):
We can have function to traverse each of the AND's and OR's, then we can evaluate the "truthiness" of the node and "hop" to the next if the state is true or false based on the user input (we would halt on NULL)
We can also have the frontend display all the node metadata when it hits the node