You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a field called superseded_by which is configured with a when condition that says "when field state equals value superseded".
In addition I want to model the semantics, if "state is superseded" that field superseded_by is mandatory (hence, required: true).
In the FrontMatter sidebar superseded_by is visible if and only if state: superseded (which goes with the intended semantics), however in the frontmatter of the markdown file the field superseded_by is already there upon content creation, even if the initial state doesn't hold that value superseded. Moreover, FrontMatter marks that field as erroneous, because it has no meaningful value yet, although at this point of time I don't want superseded_by to be validated at all - because that when condition is not fulfilled at all.
If I delete the superseded_by field manually, the error goes away.
Is there a way to:
either model my semantics properly so that this field is only validated if the corresponding when condition applies?
or prevent the field from being added into the front matter of the markdown file upon creation of the content?
By default, on content creation, it will add all fields. As I understand, this is not something you want; what you can do is, on the content type, set the clearEmpty property as true, which makes sure to remove the empty fields.
Thanks for this hint! It seems to go into the right direction, however, when I tried it out I came across another remarkable behaviour.
But first I'll paste the relevant snippets of my frontmatter.json:
{ ..."frontMatter.taxonomy.contentTypes": [ ...
{
"name": "strategic-decision",
"pageBundle": false,
"template": "[[workspace]]/templates/strategic-decision.md",
"filePrefix": null,
"clearEmpty": true,
"fields": [ ...
{
"title": "Draft",
"name": "draft",
"type": "draft",
"description": "Is this document in draft state?",
"required": true,
"default": true
},
{
"title": "State",
"name": "state",
"type": "choice",
"description": "lifecycle state of decision record",
"required": true,
"choices": ["proposed", "accepted", "rejected", "deprecated", "superseded"],
"default": "proposed",
"when": {
"fieldRef": "draft",
"operator": "eq",
"value": false
},
{
"title": "superseded by",
"name": "superseded_by",
"type": "contentRelationship",
"description": "list of references to strategic decisions that supersede that one",
"contentTypeName": "strategic-decision",
"contentTypeValue": "slug",
"required": true, // this is what we were initially talking about"multiple": true,
"when": {
"fieldRef": "state",
"operator": "eq",
"value": "superseded"
}, ... ] }
Please note the cascade of draft => state => superseded_by by conditions.
When I set clearEmpty: true, the toggle switch of draft is fixed, I can't toggle it any more. Consequently, I can't test the cascade to the end, because state does not become visible so that I could change it to superseded, then superseded_by field is also never visible in the FrontMatter sidebar.
But as you hinted, initially the superseded_by field is removed, because of clearEmpty. I just can't test its reappearance thoroughly because of the behaviour of the cascaded fields.
Good question!
According to the way my developer team defines the workflow and life cycle of decision records, we don't plan to go back to draft: true once it has arrived at draft: false, so I have not thought about this situation yet.
Independent from this I'd want superseded_by to disappear as well, because I expect the cascade of conditions to be evaluated from the beginning of the cascade on each change of values.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Relates to #707
Implemented in #709
Implemented in #710