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

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
主站蜘蛛池模板: 铜川市| 清原| 麻栗坡县| 凤阳县| 墨竹工卡县| 香格里拉县| 台南县| 玉门市| 永春县| 中牟县| 大连市| 合川市| 调兵山市| 紫阳县| 雅安市| 诸城市| 商河县| 镇康县| 东城区| 辽阳市| 唐河县| 嵩明县| 绥宁县| 昭苏县| 武清区| 汕尾市| 清原| 金门县| 板桥市| 慈溪市| 东阿县| 平山县| 五台县| 青岛市| 海原县| 姚安县| 保定市| 济源市| 会理县| 吐鲁番市| 土默特右旗|