Currently, I am implementing server-side validation for dynamically created input fields within div tags. The issue I am facing is that I need to display the API error message in my template instead of directly setting it in my controller. If I set it in the controller, it will impact all input fields.
My approach is to implement something like the following:
#Template
..<span ng-show="innerNameForm.name.$error.apiResponse">{{ msg }}</span>
..<input type="text" ng-change="msg = someFunction(inputValue, innerNameForm)"...... />
#Controller
scope.someFunction = function(value, form){
apiMsg = timeout(function() {
var prom = vcRecordValidate.name(value, record_id).then(function(promise){
//If fails... do this
form.name.$setValidity('apiResponse', false);...
return promise; //This contains the API error message
});
return prom;
}, 1000);
return apiMsg;
};
This code is just a simplified example and may be missing some unimportant details.