javascriptangularjsangular-formly

Combine model and boolean variable in expressionProperties - Formly


I want to set formly form fields disabled value based on model properties and boolean variable. This doesn't seem to work

expressionProperties: {
    'templateOptions.disabled': 'model.advancePayments && !model.deposit' || vm.acquisitionCancelledFlag
}

It works but the || vm.acquisitionCancelledFlag doesn't make any difference

vm.acquisitionCancelledFlag is true but the field isn't disabled

I have also tried

'templateOptions.disabled': '(model.advancePayments && !model.deposit) || vm.acquisitionCancelledFlag'

Solution

  • Spent some time on this but figured out I can do this instead so I'm sharing it with people who might need it. Not the most elegant but works

    expressionProperties: {
        'templateOptions.disabled': function(viewValue, modelValue, scope) {
            return (scope.model.advancePayments && !scope.model.deposit) || vm.acquisitionCancelledFlag;
        }
    }