json-schema-form / angular-schema-form

Generate forms from a JSON schema, with AngularJS!
https://json-schema-form.github.io/angular-schema-form
MIT License
2.47k stars 653 forks source link

clicking checkboxes generated by angular-schema-form cause the error 'cannot read property 'length' of undefined' #718

Closed taimoorq closed 8 years ago

taimoorq commented 8 years ago

Question

I have the following schema and form declared in my controller:

$scope.schema = { "type": "object", "properties": { "s4_0": { "type": "array", "title": "CHECKBOXES", "items": { "type": "string", "enum": [ 1, 2, 3 ] } } } };

$scope.form = [
    {
        "key": "s4_0",
        "type": "checkboxes",
        "titleMap": [
            {
                "value": "1",
                "name": "box 1"
            },
            {
                "value": "2",
                "name": "box 3"
            },
            {
                "value": "3",
                "name": "box 2"
            }
        ]
    },
    {
        "type": "submit",
        "title": "Submit"
    }
];

My view has the following form declaration:

<form name="myForm" sf-schema="schema" sf-form="form" ng-submit="onSubmit(myForm)"></form>

Actual behaviour

When rendering the checkboxes show correctly but clicking on them gives the following error

angular.js:13424 TypeError: Cannot read property 'length' of undefined at schema-form.min.js:1 at $watchCollectionAction (angular.js:16734) at Scope.$digest (angular.js:16869) at Scope.$apply (angular.js:17133) at $$debounceViewValueCommit (angular.js:26702) at $setViewValue (angular.js:26674) at HTMLInputElement.listener (angular.js:23277) at HTMLInputElement.dispatch (jquery-1.12.4.min.js:3) at HTMLInputElement.r.handle (jquery-1.12.4.min.js:3)

When i paste my schema and form into the angular-schema-form playground this works fine but in my app it keeps throwing an error. Also when submitted the value of the field gets saved as "false" instead of the array of options chosen.

Any idea what I could be doing wrong?

I would be happy to post more information that could be more helpful.

@json-schema-form/angular-schema-form-lead

taimoorq commented 8 years ago

looks like there is already a known bug thats causing this. closing this issue

taimoorq commented 8 years ago

Reopening this since this schema and form work in the playground so wondering if there's a different issue causing this not to work

Anthropic commented 8 years ago

@taimoorq I suspect your issue is related to either file ordering or model data on load, either way I can't help further without a plunker, but given it works in the demo app I suggest trying to strip out other parts of the form that may be causing the error to narrow down your search.

Please re-open if you do not feel the question has been answered sufficiently or a demo can be provided.

taimoorq commented 8 years ago

@Anthropic - I set up a simple plnkr that replicates the issue with a barebones form:

https://plnkr.co/edit/tpl:8rFfZljYNl3z1A4LKSL2?p=preview

Hoping I'm just doing something stupid

Anthropic commented 8 years ago

@taimoorq I think you forgot to save your changes to the plunker perhaps it is not showing any form code?

taimoorq commented 8 years ago

@Anthropic Sorry bad link. Let me know if this works for you:

https://embed.plnkr.co/xcQ3wfpWgPqvIZirJvdM/

taimoorq commented 8 years ago

Hey @Anthropic . Just wondering if you were able to view the plunker with that last link?

Anthropic commented 8 years ago

Hi @taimoorq I missed your follow up, thanks for the nudge!

The line of code your error is on has been removed in dev branch, could you try it with the latest build in develop? I can't see anything obvious causing it, but I am sleepy, remind me on the weekend and I will try to take a better look.

taimoorq commented 8 years ago

Thanks for the offer @Anthropic. Turned out to be a dumb mistake on my end. I didn't have a $scope.model variable set up since im using pouchdb and didn't think i needed it. Added that in and it worked. Looks like the length error is valid, just FYI.

Thanks for your help with this and apologies for the rookie mistake