danhunsaker / angular-dynamic-forms

Build Forms in AngularJS From Nothing But JSON (please see Alternatives in the README)
MIT License
379 stars 140 forks source link

Issue when putting templates into an array #29

Closed JK00 closed 10 years ago

JK00 commented 10 years ago

Hi When I put templates into an array, then use ng-repeat with , I get some error message (TypeError: undefined is not a function at m.extend.attr (http://localhost:8080/app/shared/vendor/jquery-1.11.1/jquery-1.11.1.min.js:4:10092)). I suspect this is because angular adds fields into arrays.

e.g.

If I add "if (id === '$$hashKey') { return; }" in your buildFields function, this seems to fix it...tho i'm not sure if this is the right fix.

Alternatively, if I add "track by $index" into my ng-repeat, this also seems to fix it.

danhunsaker commented 10 years ago

The track by approach is more correct as the ngRepeat goes, but I'll try to get in and add logic to strip anything with a key name starting with $. Or if you have a moment to adjust your tweak to check that instead of just the one key, I'd accept the PR. :-)

Thanks for the heads up. I suspect lots of use cases where Angular will pollute the template before ngDynForms actually sees it, so I'll need to be ready.

danhunsaker commented 10 years ago

Try it now; this should be fixed.

JK00 commented 10 years ago

Thanks. One other thing, I think on line 444, you need a if(ctrl), because your ngModel has a '?' before it. It's been giving me some errors.

danhunsaker commented 10 years ago

Hrm. ctrl is the controller responsible for that element - it has nothing to do with the ng-model attribute. Not sure of a situation where you could have an undefined ctrl there...

danhunsaker commented 10 years ago

OK, I take that back. It's the controller for the ng-model itself. Let me research this further...

JK00 commented 10 years ago

Maybe I'm wrong. I'm getting this on a screen that doesn't use dynamic-forms:

TypeError: Cannot set property '$render' of undefined at link (http://localhost:8090/app/shared/vendor/angular-dynamic-forms/dynamic-forms.js:444:24)

If I add 'if (ctrl)' on line 444, it seems ok, but that's probably a terrible hack on my part. I just needed to hack something up to demo.

danhunsaker commented 10 years ago

You're right; it should be ignoring file and range input elements that don't have ng-model on them. Not sure what use cases would benefit from not being connected to a model (traditional file uploads, I imagine, though the expansions to file handling make that easier to handle in less traditional ways - I should document those in the README sometime...), but I've pushed the fix anyway, because it is still a bug.

JK00 commented 10 years ago

One more question: if (String.charAt(id, 0) == '$') { this line is generating this error:

TypeError: undefined is not a function at buildFields (http://localhost:8090/app/shared/vendor/angular-dynamic-forms/dynamic-forms.js:92:26)

Am I doing something wrong?

danhunsaker commented 10 years ago

No. I just got lazy and took advantage of a language construct that doesn't exist in every browser. I'll adjust the line so it will actually work and repush in a bit. Sorry about that.

danhunsaker commented 10 years ago

That should fix it. Sorry about that.

JK00 commented 10 years ago

Cool. Thanks!

danhunsaker commented 10 years ago

If that's everything, I'll close this. :smile: