Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

I'm doing some input validation using angular, but when the function is called each of the elements come back as undefined. I've included the important code below, please let me know if this is not enough. I appreciate any help that I can get.

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 note, line 237 is the line that begins with elem.add. Also, somelink represents a real link, as I could not post the real one.

share|improve this question
    
can you setup a fiddler ? Also specify the full error from console –  Moiz Dec 8 '14 at 8:24
    
Sure, I've heard of it, but am not very familiar. What data would be useful to you out of it? –  aProgrammer Dec 8 '14 at 8:25
    
copy full at from console. e.g before at link there should be some error –  Moiz Dec 8 '14 at 8:27
    
I wasn't able to get it to work properly, at least I don't think so, just a bunch of ClientHello record was too long entries. I think what I've pasted below may be what you're looking for? –  aProgrammer Dec 8 '14 at 8:43
    
angular.js:10061 TypeError: undefined is not a function at link (192.168.1.252/imageinbox/IIExpress/app/assets/angular/…) at nodeLinkFn (192.168.1.252/imageinbox/IIExpress/app/assets/angular/…) <input type="MRN" ng-model="MRN2" class="form-control ng-pristine ng-valid" id="MRN2" placeholder="Confirm MRN" ng-required="" mrn-check="MRN1"> 192.168.1.252/imageinbox/IIExpress/app/?user=associate Failed to load resource: net::ERR_CACHE_MISS –  aProgrammer Dec 8 '14 at 8:44

1 Answer 1

Please try this code. The input type="MRN" => type="text"

<form name="UploadForm" class="input-group" role="form">
    <div class="input-group">
        <span class="input-group-addon">MRN</span>
        <input type="text" ng-model="MRN1" class="form-control" id="MRN1" placeholder="Patient MRN" ng-required="" />
    </div>
    <div class="input-group">
        <span class="input-group-addon">MRN</span>
        <input type="text" 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>

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() === jQuery(firstMRN).val());
                });
            });
        }
    };
}]);
share|improve this answer
    
I just tried that, and it's throwing TypeError: undefined is not a function at the first instance of elem.add –  aProgrammer Dec 8 '14 at 9:18
    
I tried at my end and it is working –  Moiz Dec 8 '14 at 9:22
    
Hmm, maybe I have it placed incorrectly in my .js file? I can upload the rest of it if you think the error resides somewhere else? (I assume it must, since it's working on your system). –  aProgrammer Dec 8 '14 at 9:31
    
setup a fiddler –  Moiz Dec 8 '14 at 9:36
    
What tab do you want the data out of? I'm sorry that this is such a basic question, but I'm not used to using fiddler. –  aProgrammer Dec 8 '14 at 9:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.