- Sencha Touch Cookbook
- Ajit Kumar
- 366字
- 2021-08-20 15:56:10
Checkbox and Checkbox group
Checkboxes permit the user to make multiple selections from a number of available options. It is a convenient way to learn about user choices. For example, in an application, we may have a checkbox asking the user if he/she stayed in Hyderabad. Moreover, if we are capturing the detail about multiple cities where the user had stayed, then we would group multiple checkboxes under one name and use them as a checkbox group. In this recipe, we will see how we can create a checkbox and a checkbox group using Sencha Touch and how to handle the values when you want to set them, or when the form data is posted.
Getting ready
Make sure that you have set up your development environment by following the recipes outlined in Chapter 1.
Make sure that you have followed the Getting your form ready with FormPanel recipe in this chapter.
How to do it...
Carry out the following steps:
- Copy
ch02_01.js
toch02_09.js
. - Open a new file named
ch02_09.js
and replace the definition offormBase
with the following code:var formBase = { items: [{ xtype: 'checkboxfield', name: 'city', value: 'Hyderabad', label: 'Hyderabad', checked: true }, { xtype: 'checkboxfield', name: 'city', value: 'Mumbai', label: 'Mumbai' }] };
- Include
ch02_09.js
in place ofch02_08.js
inindex.html
. - Deploy and access the application in the browser. You will see the checkboxes as shown in the following screenshot:
How it works...
The preceding code creates two checkboxes inside the form panel. checked: true
checks the checkbox when it is rendered. When a form is submitted, the checkbox values are returned as an array. For example, given the preceding code, when the user clicks on Submit, city would have two values, as follows:
city: ['Hyderabad', 'Mumbai']
See also
- The recipe named Setting up the Android-based development environment in Chapter 1
- The recipe named Setting up the iOS-based development environment in Chapter 1
- The recipe named Setting up the Blackberry-based development environment in Chapter 1
- The recipe named Setting up the browser-based development environment in Chapter 1
- The recipe named Setting up the production environment in Chapter 1
- The recipe named Getting your form ready with FormPanel in this chapter
- Reporting with Visual Studio and Crystal Reports
- 軟件項目管理(第2版)
- JavaScript:Functional Programming for JavaScript Developers
- 零基礎(chǔ)玩轉(zhuǎn)區(qū)塊鏈
- C/C++算法從菜鳥到達人
- 數(shù)據(jù)結(jié)構(gòu)習(xí)題精解(C語言實現(xiàn)+微課視頻)
- Essential Angular
- 零基礎(chǔ)趣學(xué)C語言
- HTML 5與CSS 3權(quán)威指南(第3版·上冊)
- 持續(xù)集成與持續(xù)交付實戰(zhàn):用Jenkins、Travis CI和CircleCI構(gòu)建和發(fā)布大規(guī)模高質(zhì)量軟件
- Buildbox 2.x Game Development
- Spring 5 Design Patterns
- C++程序設(shè)計
- Get Your Hands Dirty on Clean Architecture
- 算法超簡單:趣味游戲帶你輕松入門與實踐