Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: undefined is not a function - element[0].select() #48

Open
cougar2010 opened this issue Mar 24, 2015 · 2 comments
Open

TypeError: undefined is not a function - element[0].select() #48

cougar2010 opened this issue Mar 24, 2015 · 2 comments

Comments

@cougar2010
Copy link

In line 67 in directive.coffee element[0].select() will be returned which seems to be undefined in case of an validation error.

Console output:

TypeError: undefined is not a function
    at Object.angular.module.directive.link.rule.validator.error (angular-validator.js:63)
    at angular-validator.js:402
    at deferred.promise.then.wrappedCallback (angular.js:11682)

I think this can easily be fixed with try catch or undefined check.

@cougar2010
Copy link
Author

After a bit debugging it seems this issue only occurs if you use the validation directives not directly on a input html element. I have a custom directive for input fields (including label, input elements and some other stuff) and I'm using the validation directive on my directive instead of the input field.

Supporting this could be achieved by something like this:

try {
    return element[0].select ? element[0].select() : element.find('input')[0].select();
} catch(_error) {
    console.warn('Error trying to select element ', _error.message, element);
}

@CarbonFactory
Copy link

Thanks @cougar2010
Had a little bug in your code. Fixed it for my case. I'm using the selectize control

try {
    return element[0].select ? element[0].select() : element.parent().children().find('input')[0].select();
} 
catch (_error)  {
    console.warn('Error trying to select element ', _error.message, element);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants