I have a input element which I am trying to name dynamically, but I had no luck so far using angular js.
neither
<input type="text" name="resource.Name" ng-model="resource.Value" ng-required="resource.IsRequired">
nor
<input type="text" name="{{resource.Name}}" ng-model="resource.Value" ng-required="resource.IsRequired">
works for me. When I try to access name attribute it always comes back as resource.Name instead of the value it contains. The main reason I am trying to name this input control is validation, if user does not enter text in the field, I would like to tell them which textbox is required. If there is any angular directive I can use for that purpose I am ready to use them as well.
Can anyone tell me how to achieve this.
My validation function is as follows:
window.resourcesValidation = function ($scope, $rootScope, $alert) {
var subscriptions = $scope.scopeData.Subscriptions;
var isValidated = true;
if ($scope.resourceDataForm && $scope.resourceDataForm.$error && $scope.resourceDataForm.$error.required) {
var missingFields = [];
angular.forEach($scope.resourceDataForm.$error.required, function (value, key) {
isValidated = false;
missingFields.push("-" + value.$name);
});
$alert.error("Please fill in the all required fields.\r\n" + missingFields.join("\r\n"));
}
if (isValidated)
$scope.saveChanges(subscriptions);
return isValidated;
};
$scope.resourceDataForm
. Is$scope.resourceDataForm.$error.required
an array? Do its items have a$name
property? Can you post what the entire object looks like? – Jerrad 2 days ago