Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

md-select error on name attribute #3062

Closed
hodeyp opened this issue Jun 1, 2015 · 9 comments
Closed

md-select error on name attribute #3062

hodeyp opened this issue Jun 1, 2015 · 9 comments
Assignees
Milestone

Comments

@hodeyp
Copy link

hodeyp commented Jun 1, 2015

I need to define the name on an md-select programatically using {{id}}. However, when doing so an error is thrown...

TypeError: Cannot read property '$name' of undefined

the offending code is on line 8029 of angular-material.js...

if (attr.name && formCtrl) {
var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]')
formCtrl.$removeControl(angular.element(selectEl).controller());
}

it looks to be a timing issue of when the attr.name is bound, as a hack I put the function into a $timeout and it worked correctly.

@evoker
Copy link

evoker commented Jun 4, 2015

I am having the same issue. I am defining the name of an mdSelect directive using the following code:

<md-select name="type{{$index+1}}"

I am getting: TypeError: Cannot read property '$name' of undefined

FYI: This is part of an ng-repeat loop.

@evoker
Copy link

evoker commented Jun 5, 2015

Any word on this? For someone that cannot hack angular-material.js, this is a serious issue...

@apat183
Copy link

apat183 commented Jun 7, 2015

Same issue here (version1.4.0) even when I don't set it programatically, I can just leave it without 'name' for now but then I get no validation.

<md-input-container>
    <md-select name="addressCountry" placeholder="Country" ng-model="company.addressCountry" required>
         <md-option ng-value="country" ng-repeat="country in countries">{{ country }}</md-option>
    </md-select>
    <div class="errors" ng-messages="companyForm.addressCountry.$error" ng-show="companyForm.addressCountry.$touched && companyForm.addressCountry.$invalid">
        <div ng-message="required">Country required</div>
    </div>
</md-input-container>

I don't think there is anything wrong with my code.

@agilexs
Copy link

agilexs commented Jun 8, 2015

Have same problem, +1

it happens here:

if (attr.name && formCtrl) {
  var selectEl = element.parent()[0].querySelector('select[name=".' + attr.name + '"]')
  formCtrl.$removeControl(angular.element(selectEl).controller()); // <--- controller() returns undefined
}

aa440ef#diff-d7b463f733c2e3fbc783f38073561b74R153

Intention is unclear to me. If I step through the code in debugger, hidden select element is not part of the form anyway. If I comment this block, then it works for me. I didn't tried $timeout solution suggested by @hodeyp (can you provide the code pls?). It has to resolve #1801 somehow, but I do not use it so cannot test.

@iamisti
Copy link

iamisti commented Jun 23, 2015

+1 have the same issue.
It's working in my application, but it's failing with this issue in my integration tests.

@molog
Copy link

molog commented Jun 25, 2015

+1
@evoker I had this issue when using with ng-repeat too.

I found a workaround:
http://stackoverflow.com/questions/14378401/dynamic-validation-and-name-in-a-form-with-angularjs

which uses outer form + inner form for each ng-repeat item

@wenbolovesnz
Copy link

+1 same issue, hope this one get fixed soon.

@eXaminator
Copy link

+1

@karlhorky
Copy link
Contributor

This appears to be caused by lack of a controller around the directive.

http://codepen.io/karlhorky/pen/OVZOqy

I've opened a PR: #3671

@rschmukler rschmukler modified the milestones: 0.11.0, Backlog Jul 12, 2015
rschmukler added a commit that referenced this issue Jul 17, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

10 participants