I rely on Formly for building my forms using angularJS
Here is an example of one of my form fields:
$scope.postFields = [
{
key: 'title',
type: 'input',
templateOptions: {
label: "Title",
// required: true,
minlength: 2,
},
validation: {
messages: {
required: function(viewValue, modelValue, scope) {
return scope.to.label + ' is required'
}
}
}
}
]
I am attempting to interact with my fields in the following manner:
function failure(response) {
console.log("failure", response)
_.each(response.data, function(errors, key) {
_.each(errors, function(e) {
$scope.form[key].$dirty = true;
$scope.form[key].$setValidity(e, false);
});
});
}
This is how I have structured my formly form:
<formly-form form="postForm" model="model" fields="postFields" class="col-md-4">
<button type="submit" class="btn btn-primary" ng-click="addPost()">Submit</button>
</formly-form>
I'm encountering an error which states:
TypeError: Cannot read property 'title' of undefined
The issue seems to be on this line of code:
$scope.form[key].$dirty = true;
Is there a proper way to reference created formly fields that anyone can advise on?