Description
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.