I am attempting to add a HTML attribute to a form field to disable it if a property is true in a JSON file.
On my form field I have added data-is-disabled={{field.rules.disabled}} which is read in from the following from the JSON
"rules" : {
"disabled": "true"
}
I then have a directive in my module where I am wanting to remove that attribute and replace it with a disabled attribute to disable the field.
app.directive ('isDisabled', function($compile) {
return {
restrict: 'A',
compile: function (element) {
element.removeAttr("data-is-disabled");
element.attr("disabled");
var fn = $compile(element);
return function(scope){
fn(scope);
};
}
}
});
It seems overly complicated, however it is necessary for multiple different field type situations, in this case the field needs to be disabled.
I have tried a few different solutions from around SO, but I haven't got it working yet. The attribute remains as data-is-disabled="true".
Many thanks in advance.