Setting default values isnt possible in the XML schema itself
joncorrin opened this issue · comments
I'm trying to use the following XML to create a default value if a parameter doesnt exist. I realize the c-if attribute only works with null or undefined values (hide if so). It would be nice to be able to add the bang symbol !
or to set a default value:
<PolicyInfo>
<PolicyTerm c-if="PolicyInfo.PolicyTerm">{{PolicyInfo.PolicyTerm}}</PolicyTerm>
<PolicyTerm c-if="!PolicyInfo.PolicyTerm">6 Month</PolicyTerm>
<Package c-if="PolicyInfo.Package">{{PolicyInfo.Package}}</Package>
<Package c-if="!PolicyInfo.Package">No</Package>
<Effective c-if="PolicyInfo.Effective">{{PolicyInfo.Effective|YYYYMMDD}}</Effective>
<CreditCheckAuth>Yes</CreditCheckAuth>
</PolicyInfo>
Should resolve to the following if all values are null
<PolicyInfo>
<PolicyTerm>6 Month</PolicyTerm>
<Package>No</Package>
<CreditCheckAuth>Yes</CreditCheckAuth>
</PolicyInfo>
Or something like this would work well:
<PolicyInfo>
<PolicyTerm>{{PolicyInfo.PolicyTerm || '6 Month'}}</PolicyTerm>
<Package>{{PolicyInfo.Package || 'No'}}</Package>
<Effective>{{PolicyInfo.Effective|YYYYMMDD || '2020/05/20'}}</Effective>
<CreditCheckAuth>Yes</CreditCheckAuth>
</PolicyInfo>
The https://github.com/wspringer/cruftless/tree/feature/default-values branch as some changes that might be what you are looking for. Let me know if this would solve your issue:
https://github.com/wspringer/cruftless/tree/feature/default-values#default-values