官术网_书友最值得收藏!

  • Sencha Touch Cookbook
  • Ajit Kumar
  • 455字
  • 2021-08-20 15:56:08

Working with search

In this and the subsequent recipes of the chapter, we will go over each of the form fields and understand how to work with them. This recipe describes the steps required to create and use a search form field.

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.

How to do it...

Carry out the following steps:

  1. Copy ch02_01.js to ch02_02.js.
  2. Open a new file named ch02_02.js and replace the definition of formBase with the following code:
    var formBase = {
      items: [{
        xtype: 'searchfield',
        name: 'search',
        label: 'Search'
      }]
    };
  3. Include ch02_02.js in place of ch02_01.js in index.html.
  4. Deploy and access the application in the browser. You will see a form panel with a search field.

How it works...

The search field can be constructed by using the Ext.form.Search class instance or by using the xtypesearchfield . The search form field implements HTML5 <input> with type="search". However, the implementation is very limited. For example, the HTML5 search field allows us to associate a data list to it which it can use during the search, whereas this feature is not present in Sencha Touch. Similarly, the W3 search field spec defines a pattern attribute to allow us to specify a regular expression against which a User Agent is meant to check the value, which is not supported yet in Sencha Touch. For more detail, you may refer to the W3 search field (http://www.w3.org/TR/html-markup/input.search.html) and the source code of the Ext.form.Search class.

There's more...

Often, in the application, for the search fields we do not use a label. Rather, we would like to show a text, such as Search inside the field that will disappear when the focus is on the field. Let's see how we can achieve this.

Using a placeholder

Placeholders are supported by most of the form fields in Sencha Touch by using the property placeHolder. The placeholder text appears in the field as long as there is no value entered in it and the field does not have the focus. The following code snippet shows the typical usage of it:

{
   xtype: 'searchfield',
   name: 'search',
   label: 'Search',
   placeHolder: 'Search...'
}

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
主站蜘蛛池模板: 星子县| 马关县| 巴林左旗| 洪泽县| 大兴区| 巴楚县| 涪陵区| 德州市| 庆云县| 洛浦县| 光泽县| 固安县| 罗江县| 云和县| 敦化市| 泾源县| 盐亭县| 旅游| 丰台区| 吉安市| 岐山县| 阿鲁科尔沁旗| 瓦房店市| 扶绥县| 苗栗市| 上杭县| 保康县| 成都市| 泽普县| 称多县| 壶关县| 黄骅市| 顺平县| 太白县| 蕉岭县| 安丘市| 临邑县| 北辰区| 新巴尔虎左旗| 杭锦旗| 乌兰察布市|