aboutsummaryrefslogtreecommitdiffstats
path: root/documentation/components/components-checkbox.asciidoc
blob: 4e84010b6a60fd1273b7ec4c4e4f002fb318cc2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: CheckBox
order: 15
layout: page
---

[[components.checkbox]]
= [classname]#CheckBox#

ifdef::web[]
[.sampler]
image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/other/check-box"]
endif::web[]

[classname]#CheckBox# is a two-state selection component that can be either
checked or unchecked. The caption of the check box will be placed right of the
actual check box. Vaadin provides two ways to create check boxes: individual
check boxes with the [classname]#CheckBox# component described in this section
and check box groups with the [classname]#OptionGroup# component in multiple
selection mode, as described in
<<dummy/../../../framework/components/components-optiongroup#components.optiongroup,"OptionGroup">>.

Clicking on a check box will change its state. The state is a
[classname]#Boolean# property that you can set with the [methodname]#setValue()#
method and obtain with the [methodname]#getValue()# method of the
[classname]#Property# interface. Changing the value of a check box will cause a
[classname]#ValueChangeEvent#, which can be handled by a
[classname]#ValueChangeListener#.


[source, java]
----
CheckBox checkbox1 = new CheckBox("Box with no Check");
CheckBox checkbox2 = new CheckBox("Box with a Check");

checkbox2.setValue(true);

checkbox1.addValueChangeListener(event -> // Java 8
    checkbox2.setValue(! checkbox1.getValue()));

checkbox2.addValueChangeListener(event -> // Java 8
    checkbox1.setValue(! checkbox2.getValue()));
----

The result is shown in <<figure.components.checkbox.basic>>.

[[figure.components.checkbox.basic]]
.An Example of a Check Box
image::img/checkbox-example1.png[]

For an example on the use of check boxes in a table, see
<<dummy/../../../framework/components/components-table#components.table,"Table">>.

== CSS Style Rules


[source, css]
----
.v-checkbox { }
  .v-checkbox > input { }
  .v-checkbox > label { }
----

The top-level element of a [classname]#CheckBox# has the
[literal]#++v-checkbox++# style. It contains two sub-elements: the actual check
box [literal]#++input++# element and the [literal]#++label++# element. If you
want to have the label on the left, you can change the positions with "
[literal]#++direction: rtl++#" for the top element.
>"grunt-eslint": "22.0.0", "grunt-git-authors": "3.2.0", "grunt-jsonlint": "1.1.0", "grunt-karma": "3.0.1", "grunt-newer": "1.3.0", "gzip-js": "0.3.2", "husky": "1.3.1", "insight": "0.10.1", "jsdom": "14.0.0", "karma": "4.0.1", "karma-browserstack-launcher": "1.5.1", "karma-chrome-launcher": "2.2.0", "karma-firefox-launcher": "1.1.0", "karma-ie-launcher": "1.0.0", "karma-jsdom-launcher": "7.1.0", "karma-qunit": "3.0.0", "load-grunt-tasks": "4.0.0", "native-promise-only": "0.8.1", "promises-aplus-tests": "2.1.2", "q": "1.5.1", "qunit": "2.9.2", "raw-body": "2.3.3", "requirejs": "2.3.6", "rimraf": "3.0.0", "rollup": "1.27.6", "sinon": "7.3.1", "strip-json-comments": "2.0.1", "testswarm": "1.1.0", "uglify-js": "3.4.7" }, "scripts": { "build": "npm install && grunt", "start": "grunt watch", "test:browserless": "grunt && grunt test:slow", "test:browser": "grunt && grunt karma:main", "test:esmodules": "grunt && grunt karma:esmodules", "test:amd": "grunt && grunt karma:amd", "test:no-deprecated": "grunt test:prepare && grunt custom:-deprecated && grunt karma:main", "test:slim": "grunt test:prepare && grunt custom:slim && grunt karma:main", "test": "npm run test:slim && npm run test:no-deprecated && grunt && grunt test:slow && grunt karma:main && grunt karma:esmodules && grunt karma:amd", "jenkins": "npm run test:browserless" }, "commitplease": { "nohook": true, "components": [ "Docs", "Tests", "Build", "Support", "Release", "Core", "Ajax", "Attributes", "Callbacks", "CSS", "Data", "Deferred", "Deprecated", "Dimensions", "Effects", "Event", "Manipulation", "Offset", "Queue", "Selector", "Serialize", "Traversing", "Wrap" ], "markerPattern": "^((clos|fix|resolv)(e[sd]|ing))|^(refs?)", "ticketPattern": "^((Closes|Fixes) ([a-zA-Z]{2,}-)[0-9]+)|^(Refs? [^#])" }, "husky": { "hooks": { "commit-msg": "node node_modules/commitplease", "pre-commit": "grunt lint:newer qunit_fixture" } } }