I am facing an issue where one of my fields in the form should be mandatory or not based on a boolean variable. Even if the variable changes, the field always remains required. I'm puzzled about why my
expressionProperties templateOptions.required
is not working as expected to trigger this change.
This problem is within my Formly form setup.
vm.showDeleteButton = false;
vm.fields = [
{
className: 'row',
fieldGroup: [
{
className: 'col-xs-6',
key: 'transferDate',
type: 'datepicker',
templateOptions: {
label: 'Deallocation Date',
type: 'text',
datepickerPopup: 'dd/MM/yyyy',
minDate: vm.model.minDate,
maxDate: vm.model.maxdate,
},
expressionProperties: {
'templateOptions.required': !vm.showDeleteButton
}
}
]
}
];
I have also attempted another solution:
expressionProperties: {
'templateOptions.required': function() {
if(!vm.showDeleteButton) {
return true;
else {
return false;
}
}
}
Despite reading the Formly expressions documentation, I couldn't find a resolution to my issue.
Below is the HTML code snippet as requested:
<formly-form model="vm.model" fields="vm.fields" options="vm.options" form="vm.form"></formly-form>