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

Checklist #1

Closed
tonyhayes opened this issue Mar 13, 2014 · 12 comments
Closed

Checklist #1

tonyhayes opened this issue Mar 13, 2014 · 12 comments
Assignees
Labels

Comments

@tonyhayes
Copy link

Hi -- I'm trying to populate my check list from stored json data
region: {1:true}

But it isn't being checked in the form;

    var dynamicForm =  {
        "region": {
            "type": "checklist",
            "label": "Region",
            "options": {
                "1": {
                    "label": "North East"
                },
                "2": {
                    "label": "All"
                },
                "3": {
                    "label": "South Texas"
                },
                "4": {
                    "label": "Permian"
                },
                "5": {
                    "label": "Mid Continent"
                },
                "15": {
                    "label": "West"
                }
            }
        }
    };

Any thoughts ?
I have other components and they are populating correctly.

tony@drillmap.com

@danhunsaker
Copy link
Owner

The only thing I can think of offhand is that the keys need to be the same data type - that is, they need to both be strings. But I'd assume you know that already, and that your stored JSON data from which you're restoring values is actually encoded as "region": {"1": true} - which would mean that isn't the problem. Unfortunately, in order to be more help, I'd probably need to see more of your code...

@tonyhayes
Copy link
Author

this might be a little boring for you .. but here goes ... (also I've gone back and forth on the quotation marks -- it makes no difference - and it works on the other form types.

this is part of a data structure with test data

                {
                    id:2,
                    customer: "ba1d6149-1545-411f-9e45-20dc82f1a438",
                    salesPerson: 15,
                    contact: 1,
                    opportunityForm: {
                        location: 15,
                        revenueSchedule: 1,
                        status: 1,
                        typeConversation: 1,
                        dealDate: "2014-03-13",
                        region: {"1":true}
                    },

in the view I have the following snippet;

            <fieldset>

                <dynamic-form class="col-md-12" template="opportunityFormTemplate" ng-model="master.opportunityForm">
                    <legend>dynamic form test</legend>
                </dynamic-form>

            </fieldset>

In my controller I have;

       /*

        Dynamic form processing


         */

        $scope.opportunityFormTemplate = dynamicFormService.getDynamicForm();

You have seen my service, but I'll reprint (Every is working correctly except for the checklist)

   .service('dynamicFormService', function () {
        this.getDynamicForm = function () {
            return dynamicForm;
        };


        var dynamicForm =  {
             "dealDate": {
                "type": "date",
                "label": "Deal Date",
                "placeholder": "date"
            },
            "status": {
                "type": "select",
                "label": "Status",
                "empty": "nothing selected",
                "options": {
                    "1": {
                        "label": "won"
                    },
                    "2": {
                        "label": "loss"
                    },
                    "3": {
                        "label": "pending"
                    }
                }
            },
            "location": {
                "type": "select",
                "label": "Location",
                "empty": "nothing selected",
                "options": {
                    "15": {
                        "label": "London"
                    },
                    "2": {
                        "label": "Houston"
                    },
                    "3": {
                        "label": "Austin"
                    }
                }
            },
            "typeConversation": {
                "type": "select",
                "label": "Type of Conversation",
                "empty": "nothing selected",
                "options": {
                    "1": {
                        "label": "New Business"
                    },
                    "2": {
                        "label": "Proposal"
                    },
                    "3": {
                        "label": "Continuing Business"
                    },
                    "4": {
                        "label": "Follow-up"
                    },
                    "5": {
                        "label": "Meeting"
                    }
                }
            },
            "revenueSchedule": {
                "type": "select",
                "label": "Revenue Schedule",
                "empty": "nothing selected",
                "options": {
                    "1": {
                        "label": "daily"
                    },
                    "2": {
                        "label": "weekly"
                    },
                    "3": {
                        "label": "monthly"
                    },
                    "4": {
                        "label": "yearly"
                    }
                }
            },
            "region": {
                "type": "checklist",
                "label": "Region",
                "options": {
                    "1": {
                        "label": "North East"
                    },
                    "2": {
                        "label": "All"
                    },
                    "3": {
                        "label": "South Texas"
                    },
                    "4": {
                        "label": "Permian"
                    },
                    "5": {
                        "label": "Mid Continent"
                    },
                    "15": {
                        "label": "West"
                    }
                }
            }
        };

    })

@tonyhayes
Copy link
Author

fyi -- I just tried it exactly like you suggested

"region": {"1": true}

and no joy.

@danhunsaker
Copy link
Owner

I was thinking of strict JSON, which requires object property names to be capitalized... The notation used within JavaScript is considerably more forgiving.

I think I found the issue, though... Stupidly, I'm setting the model value to {} without checking whether it is already set first. This happens on line 137. I'll fix this real quick and push a new version. Might be a few minutes because I want to make sure I get all of these little mistakes...

danhunsaker added a commit that referenced this issue Mar 13, 2014
… compile

Resolves GitHub issue #1

Signed-off-by: Daniel Hunsaker <danhunsaker@gmail.com>
danhunsaker added a commit that referenced this issue Mar 13, 2014
… compile

Resolves GitHub issue #1

Signed-off-by: Daniel Hunsaker <danhunsaker@gmail.com>
@danhunsaker
Copy link
Owner

That should fix it. Care to give it a try?

@tonyhayes
Copy link
Author

Sxsw baby (I’m in austin.tx)— I’ll try in the morning if you don’t mind — thanks for your help — really nice work … (I’ll let you know)

@tonyhayes
Copy link
Author

not that I’m pushing (I’m not — I’m very happy with what you have achieved) … as an alternative I tried the select with the muiltiple option — it either has the same problem or I couldn’t figure out how to configure the object.

@danhunsaker
Copy link
Owner

The way Angular handles model values for various form elements isn't necessarily intuitive. For a select with multiple, the model needs to contain an array of option keys: region: ["1"] in your example. Otherwise, the form template simply needs checklist changed to select, and multiple: true added, and everything should work. Just tested this using your code with the modifications mentioned above, in fact.

While the way Angular sets up models for form elements is outside my control, and therefore the scope of this module's documentation, I really should document how my code sets up models for the handful of "elements" I made up (checklist being one).

@tonyhayes
Copy link
Author

nicely working.

thanks for your help.

@tonyhayes
Copy link
Author

just so you are aware, I think there may be a bug on the line you revised.

If I pass in a {} model - I get a type error:

TypeError: Cannot read property 'region' of undefined
    at http://localhost:8888/app/lib/dynamic-forms.js:137:52
    at Object.forEach (http://localhost:8888/app/lib/angular/angular.js:329:20)
    at http://localhost:8888/app/lib/dynamic-forms.js:74:21
    at deferred.promise.then.wrappedCallback (http://localhost:8888/app/lib/angular/angular.js:11046:81)
    at deferred.promise.then.wrappedCallback (http://localhost:8888/app/lib/angular/angular.js:11046:81)
    at http://localhost:8888/app/lib/angular/angular.js:11132:26
    at Scope.$get.Scope.$eval (http://localhost:8888/app/lib/angular/angular.js:12075:28)
    at Scope.$get.Scope.$digest (http://localhost:8888/app/lib/angular/angular.js:11903:31)
    at Scope.$get.Scope.$apply (http://localhost:8888/app/lib/angular/angular.js:12179:24)
    at don

@tonyhayes
Copy link
Author

I might be wrong — In a subsequent test, I’m not observing this — must be something with one of my objects.

@danhunsaker
Copy link
Owner

Since it sounds like this error didn't reappear, I'll close this issue. Feel free to reopen it if needed.

danhunsaker added a commit that referenced this issue Apr 27, 2014
Addresses BitBucket Issue #1, and GitHub Issue #4

Signed-off-by: Daniel Hunsaker <danhunsaker@gmail.com>
danhunsaker added a commit that referenced this issue Apr 29, 2014
Addresses BitBucket issue #1

Seeing if creating the elements (`ng-form` specifically, but also the various templated elements
in case we decide to add nonstandard ones later, though I'd prefer not to, at the moment...) *before*
handing them to jqLite/jQuery (rather than having the jQ* lib handle element creation from raw HTML)
will make IE versions before 9 (specifically 8, but I'll also test older versions if I can, once it
works in 8) actually treat the elements as usable - at the moment they cannot have children, for some
reason.

Signed-off-by: Daniel Hunsaker <danhunsaker@gmail.com>
danhunsaker added a commit that referenced this issue Apr 29, 2014
Addresses BitBucket issue #1

Further testing in IE 8 showed that more elements needed to be created manually instead of by jQuery/jqLite.

Also updated the README with steps for IE 8 support.  IE 6 and 7 have limited support, even for Angular
itself.  Neither version will be targeted in the near future.  IE 8 support is still not a guarantee,
especially since Angular will only partially support it themselves, but it is much stronger than it was.

Updated the demo project with the IE 8 "hacks" needed to get it working in that browser.

Signed-off-by: Daniel Hunsaker <danhunsaker@gmail.com>
@danhunsaker danhunsaker self-assigned this Jun 16, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants