Skip to content

Instantly share code, notes, and snippets.

@avwilks
Last active May 27, 2021 15:13
Show Gist options
  • Save avwilks/fa6a6a96c89a6fa535660b4112af1236 to your computer and use it in GitHub Desktop.
Save avwilks/fa6a6a96c89a6fa535660b4112af1236 to your computer and use it in GitHub Desktop.
Conditional Fields Example Document
{
"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'"
}
}
}
@avwilks
Copy link
Author

avwilks commented May 26, 2021

Where do we store the show condition in this concept? With the rest of the metadata?

@cjohnson741
Copy link

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

@cjohnson741
Copy link

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