Skip to content

Getting selected item(s) in "checkboxes" #537

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

Closed
fabiomcj opened this issue Sep 9, 2015 · 3 comments
Closed

Getting selected item(s) in "checkboxes" #537

fabiomcj opened this issue Sep 9, 2015 · 3 comments

Comments

@fabiomcj
Copy link

fabiomcj commented Sep 9, 2015

Hi, I would not make a trivial question, but how can I get the "selected items" of the checkboxes in a function of my controller?
This is my use case: I have some checkboxes, I want to call a function every time an item is selected. inside this function I must know what item(s) is selected because for each item I want to perform different actions (like adding some extra field in my form schema and definition).
This is my approach:
Schema:

{
            type : "object",
            title : "Reporting",
            properties : {
            ......
                needs_procedures : {
                    type : "array",
                    items : {
                        type : "string",
                        enum : [ "1", "2", "3" ]
                    }
                }

            }
}

FormDef:

{
    type : "section",
    htmlClass : "col-xs-6",
    items : [ {
        key : "needs_procedures",
        title : "Procedures",
        type : "checkboxes",
            onChange : "itemSelected(form.key, model.needs_procedures)",
        titleMap : [ {
                value : "1",
                name : "pneumological examination"
                }, {
                value : "2",
                name : "cardiologic examination"
                    }, {
                value : "3",
                name : "spirometry"
                }, {
                value : "4",
                name : "electrocardiogram"
                } ],
                } ]
            }

"needs_procedures" field is inside a section, that is inside a section, that is inside a fieldset, that is inside a tab structure.
In my controller

$scope.itemSelected = function(key, value) {
        console.log(key);
        console.log(value);     
    };

The First time that an element is checked the function itemSelected() is called, but in the second parameter I have a empty array.
The second time I have an array with one element: the previous...
the third time I have an array with two elements: the two previous...
and so on...
Then it is as if the method is invoked immediately before the model is updated.

@Anthropic
Copy link
Member

@fabiomcj can you make a plunker demo or gist for us?

@Anthropic
Copy link
Member

Anthropic commented Apr 18, 2016

We are probably going to add arrayIndeces soon so you can traverse your model more easily. But a plunker/gist would help.

@Anthropic
Copy link
Member

Please re-open if you can provide more information to help us to help you :)

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

No branches or pull requests

4 participants