Currently, I am working on input validation using Angular. However, when the function is triggered, all elements return as undefined. The crucial code snippets are provided below, but do let me know if you need more information. Your assistance is greatly appreciated.
JS
angular.module('app.directives', [])
.directive('mrnCheck', [function () {
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
//console.log(firstMRN.val());
var firstMRN = '#' + attrs.mrnCheck;
elem.add('test');
//console.log(firstMRN.val());
//console.log(firstMRN);
elem.add(firstMRN).on('keyup', function () {
scope.$apply(function () {
ctrl.$setValidity('mrnmatch', elem.val() === $(firstMRN).val());
});
});
}
}
}]);
HTML
<div class = "row" ng-show="<?php echo $_SESSION["associate"]; ?>">
</br>
<form name = "UploadForm" class="input-group" role="form">
<div class="input-group">
<span class="input-group-addon">MRN</span>
<input type="MRN" ng-model="MRN1" class="form-control" id="MRN1" placeholder="Patient MRN" ng-required="" />
</div>
</br>
<div class="input-group">
<span class="input-group-addon">MRN</span>
<input type="MRN" ng-model="MRN2" class="form-control" id="MRN2" placeholder="Confirm MRN" ng-required="" mrn-Check="MRN1" />
<span ng-show="UploadForm.MRN2.$error.MRNmatch">MRN values must match!</span>
</div>
</form>
</div>
Error
at link (httpsomeLink/imageinbox/IIExpress/app/app.js:237:9) at nodeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6704:13) at compositeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6098:13) at compositeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6101:13) at nodeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6698:24) at compositeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6098:13) at nodeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6698:24) at compositeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6098:13) at compositeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6101:13) at nodeLinkFn (httpsomeLink/imageinbox/IIExpress/app/assets/angular/angular.js:6698:24)
Please be aware that line 237 corresponds to the line starting with elem.add. Additionally, somelink is a substitute for an actual link that could not be posted here.