Layout evaluations are not executed
I think I have a bit of a logical implementation issue with the HTML renderer and Model::resolve() functions. Basically, we are executing the evaluations during the resolve
stage, which I now think is incorrect. This was in an attempt to limit the need to process fields in the renderer if they were not being shown.
However, this means that when the layouts are resolved, which only happens in the renderers, the evaluations are not executed so if an evaluation is overridden in the layout, it will not work.
As an example, take this form definition:
{
"name": "Sandbox",
"description": "Example form to use for development.",
"author": "[email protected]",
"version": "1.0",
"pages": [
{
"label": "Page Number One",
"sections": [
[
{
"fields": [
"obj"
]
}
]
]
}
],
"fields": {
"obj": {
"layout": [
[
"status",
[
{
"name": "dateApproved",
"show": "item.status == 'A'"
},
{
"name": "dateApproved",
"label": "End Date",
"show": "item.status == 'C'"
}
]
]
],
"fields": {
"status": {
"label": "Status",
"options": {
"A": "Current",
"C": "Ceased"
}
},
"dateApproved": {
"type": "date",
"label": "Date Approved",
"keep": true
}
}
}
}
}
What should happen in the HTML output here is, Date Approved should only appear if Status is Current, and End Date should only appear instead if Status is Ceased. However, what i get is:
This is because the evaluations are in the layout
section and never actually get executed.
Fix for this is two steps:
- Remove the evaluations from the
resolve()
stage so that all fields are resolved. - Add the evaluations to the renderer and allow it to decide if a field should be shown AFTER it has resolved the layouts.