- Sencha Touch Cookbook
- Ajit Kumar
- 444字
- 2021-08-20 15:56:10
Text and TextArea
Text fields are one of the initial fields which allow the user to enter data in a form. Text area allows entering multiple lines of text. In this recipe, we will make use of the text and text area related classes.
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_10.js
. - Open a new file named
ch02_10.js
and replace the definition offormBase
with the following code:var formBase = { items: [ { xtype: 'textfield', name : 'firstName', label: 'First Name' }, { xtype: 'textfield', name : 'lastName', label: 'Last Name' }, { xtype: 'textareafield', name : 'detail', label: 'Detail' } ] };
- Include
ch02_10.js
in place ofch02_09.js
inindex.html
. - Deploy and access the application in the browser.
How it works...
In the preceding code, we created two text fields and a text area. Text field can be constructed by using the Ext.form.Text
class instance or by using the xtype
—textfield
. Similarly, a text area can be constructed by using the Ext.form.TextArea
class instance or by using xtype
—textareafield
. Internally, the text form field implements the HTML <input>
element with type="text"
whereas text area implements the HTML <textarea>
element. There is no validation on these fields, hence the user is allowed, by default, to enter any kind of value.
There's more...
By default, a text field or a text area allows entering any number of characters. However, in some specific scenarios, we may have to limit this to a particular value in our application. Let's see how we can limit this.
Both text field and text area support a property named maxLength
which controls the number of characters the user can enter. If this property is set to 20, then the user can only enter 20 characters. The following code snippet shows how to do this:
{ xtype: 'textfield', name : 'firstName', maxLength: 20, label: 'First Name' }, { xtype: 'textareafield', name : 'detail', maxLength: 80, label: 'Detail' }
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
- Java EE 6 企業級應用開發教程
- Cross-platform Desktop Application Development:Electron,Node,NW.js,and React
- 動手玩轉Scratch3.0編程:人工智能科創教育指南
- MySQL 8 DBA基礎教程
- Learning Network Forensics
- C語言課程設計
- 新一代SDN:VMware NSX 網絡原理與實踐
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- Django實戰:Python Web典型模塊與項目開發
- 微課學人工智能Python編程
- Learning TypeScript
- Elastix Unified Communications Server Cookbook
- 大話代碼架構:項目實戰版
- 虛擬現實:引領未來的人機交互革命
- 生成藝術:Processing視覺創意入門