CheckboxGroupView

The CheckboxGroup view

Description

The CheckboxGroup view displays a group of checkboxes, allowing you to populate a set of checkboxes with a search. You can also use this view like a standard HTML checkbox group.

Library path

Simple XML wrapper

Properties

Name

Default value

Description

id Required. The unique ID for this control.
choices[]A static dictionary of choices for the checkbox group. If bound to a managerid, the static choices specified here are prepended to the dynamic choices from the search.
For example:
var mychoices = [
    {label:"text1", value: "value1"},
    {label:"text2", value: "value2"},
    {label:"text3", value: "value3"}
];
defaultThe value of the choices that are selected by default. Multiple default choices can only be set in JavaScript as an array.
disabledfalseIndicates whether to disable the view.
initialValueThe initial value of the input. If defaultis specified, it overrides this value.
labelField""The text or search field to use as the labels for the checkboxes in this group. If labelField is not defined, the valueField is used as the label.
manageridnullThe ID of the search manager to bind this control to.
settingsThe properties of the view. See the methods below to get and set values.
valueA comma-separated list of values that are currently selected.
valueField""The value, or search field to provide the value, for the checkboxes in this group.

Methods

Name

Description

getDisplayedChoicesRetrieves a dictionary of the selected choices and their values in the following format:
[
    {value: 'val1', label: 'Value 1'},
    {value: 'val2', label: 'Value 2'},
    ...
]
renderDraws the control to the screen. Called only when you create the view manually.
settings.get( property )Returns the value of property for the current component.
settings.set( propertyvalue )Sets the value of property to the specified value for the current component.
valReturns an array of values for the checked items if passed no parameters. Sets the checked items if passed an array of values.

Events

Name

Description

changeFired when the value of the view changes.

Example

require([
    "splunkjs/mvc",
    "splunkjs/mvc/checkboxgroupview",
    "splunkjs/mvc/simplexml/ready!"
], function(mvc, CheckboxGroupView) {

    // Instantiate components
    new CheckboxGroupView({
        id: "example-checkboxgroup",
        default: "One, Three",
        el: $("#mycheckboxgroupview")
    }).render();

    // Define choices
    var choices = [
        {label: "One", value: "One"},
        {label:" Two", value: "Two"},
        {label:" Three", value: "Three"}];
     
    // Assign choices to the checkbox group
    splunkjs.mvc.Components.get("example-checkboxgroup").settings.set("choices", choices); 
});