In this tutorial i want to show you how to masking a form when user enter a submit button, statusbar that used in this tutorial is from the Extjs ux example, so I borrow this cause it is useable plugin, like always on the server side process I use simple PHP scripting. I created this post because when I used a form in Extjs and the user make a request it seem not really responsive, the system should interact the user, inform what is going on in the system and most user is not advance user. Let’s get started:
1. Setting the StatusBar
Copy the StatusBar css file and icon from the default examples to your desired folder, first the css file you can find it in “extjs/examples/ux/statusbar/css/statusbar.css”, I copy it to another folder called “css” and next the statusbar icon is in “/extjs/examples/ux/statusbar/images” and I copy all the icon files to another folder called “img” most the file structure you can see it on the image on the right, this is how it look in Netbeans project. You can see the “form_masking.html” and “server_response.php” file, this is the main file that we have to create, and it will be mentioned on the next step, but before that we have to edit the StatusBar.css file that we have copied so the icon can be loaded, by changing the “background-image” properties. So find this all code like this
view sourceprint?
1 background-image: url(../images/loading.gif);
Change the background-image to to this code, and do this to all background-image but you only need to change the url path not the image file
view sourceprint?
1 background-image: url(../img/loading.gif);
2. Create the main file
Like usual include EXTJS file in your html header, but this time you need to include the StatusBar.css that you have modified and the StatusBar.js (I don’t modified this file, this file directly linked from the Extjs ux examples, you can found it bundled on the examples)
view sourceprint?
1 <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css"/>
2 <link rel="stylesheet" type="text/css" href="css/StatusBar.css"/>
3 <script type="text/javascript" src="extjs/adapter/ext/ext-base.js"></script>
4 <script type="text/javascript" src="extjs/ext-all.js"></script>
5 <script type="text/javascript" src="extjs/examples/ux/statusbar/StatusBar.js"> </script>
3. Create the Form, Function Handler and the Window
I Create a file named “form_masking.html”, the form is similar to the form from the previous post, but in this code I added the key EventObject on the form, so when user press enter on the form, it will submit the form like the traditional html form
view sourceprint?
01 <script type="text/javascript">
02 Ext.onReady(function(){
03 var formMasking = new Ext.FormPanel({
04 frame: false, border: false, buttonAlign: 'center',
05 url: 'server_response.php', method: 'POST', id: 'frmMasking',
06 bodyStyle: 'padding:10px 10px 15px 15px;background:#dfe8f6;',
07 labelWidth: 150, width: 300,
08 items: [{
09 xtype: 'textfield',
10 fieldLabel: 'Username',
11 name: 'username',
12 id: 'formUsername',
13 allowBlank: false
14 }, {
15 xtype: 'textfield',
16 fieldLabel: 'Password',
17 name: 'password',
18 id: 'formPassword',
19 allowBlank: false,
20 inputType: 'password'
21 }
22 ],
23 keys: [
24 { key: [Ext.EventObject.ENTER], fn: fnLogin }
25 ],
26 buttons: [
27 { text: 'Login', handler: fnLogin },
28 { text: 'Reset', handler: function() {
29 formMasking.getForm().reset();
30 }
31 }
32 ]
33 });
34
35 function fnLogin() {
36 // this function must before
37 Ext.getCmp('frmMasking').on({
38 beforeaction: function() {
39 Ext.getCmp('winMask').body.mask();
40 Ext.getCmp('sbWin').showBusy();
41 }
42 });
43
44 formMasking.getForm().submit({
45 success: function() {
46 Ext.getCmp('winMask').body.unmask();
47 Ext.getCmp('sbWin').setStatus({
48 text: 'Login success !',
49 iconCls: 'x-status-valid'
50 });
51 },
52 failure: function(form, action) {
53 Ext.getCmp('winMask').body.unmask();
54 if (action.failureType == 'server') {
55 obj = Ext.util.JSON.decode(
56 action.response.responseText);
57 Ext.getCmp('sbWin').setStatus({
58 text: obj.errors.reason,
59 iconCls: 'x-status-error'
60 });
61 } else {
62 if (typeof(action.response) == 'undefined') {
63 Ext.getCmp('sbWin').setStatus({
64 text: 'Field cannot be empty !',
65 iconCls: 'x-status-error'
66 });
67 } else {
68 Ext.Msg.alert('Warning!',
69 'Server is unreachable : '
70 + action.response.responseText);
71 }
72 }
73 }
74 });
75 }
76
77 var winMasking = new Ext.Window({
78 title: 'EXTJS — Window Masking', layout: 'fit',
79 width: 350, height: 150, resizable: false, closable: false,
80 items: [formMasking], id:'winMask',
81 bbar: new Ext.ux.StatusBar({
82 text: 'Ready',
83 id: 'sbWin',
84 iconCls: 'x-status-saved'
85 })
86 });
87
88 winMasking.show();
89 });
90 </script>
4. The Function Handler
The function handler name is “fnLogin” as you can see on the code above (on the step 3), when the form submitted the event on beforeaction is called an it masking the window, why not mask the form? because when I try mask the form it will only masked the fieldLabel and the textField but not the button, so just mask the window and it will mask everything inside it. The beforeaction event have to be defined before the form submit function, or it wil not work.
5. Create The Server Response
I Create a file named “server_response.php”, the php code is the same as the previous post, it just checking username from the hardcoded array.
view sourceprint?
01 <?php
02
03 $username_list = array('admin', 'administrator', 'superadmin', 'john', 'michael');
04 if (in_array($_POST['username'], $username_list)) {
05 echo "{success:true}";
06 }
07 else {
08 echo "{success:false, errors: { reason: 'User not found !' }}";
09 }
10
11 ?>
The expected screen should be like the image below, the form when in the default condition, loading, give the error message, and when the success is achieved.
If you want another form load masking example there a sample by Saki here (I think it is more advanced), or if you like to add more advance StatusBar validation you can learn the official samples here. Finally like always I provide the code the be downloaded but I’m not included the Extjs file, you can download it from the official website, here.
DOWNLOAD SOURCE
分享到:
相关推荐
首先,我们来看看“ExtJs:收集基于ExtJs扩展的一些控件”。这个文件可能是对一些自定义或第三方开发的ExtJs控件的概述,它可能包括了各种特定用途的组件,如日历控件、拖放功能、树形视图、图表插件等。这些控件...
根据提供的文件信息,本文将详细解释ExtJs 4.2中Window组件的一些常用配置属性以及方法,帮助读者更好地理解和使用这些功能。 ### ExtJs 4.2 Window 组件概述 ExtJs 是一个基于 JavaScript 的开源框架,用于创建...
`Ext.form.Panel`是Extjs4提供的一个用于创建复杂表单的组件。它允许开发者构建包含多个输入字段、按钮以及其他交互元素的表单,并且提供了大量的功能来帮助处理表单数据,如验证、提交以及数据绑定等。 ### 二、...
在EXTJS3中,开发Web应用时经常需要创建可弹出的窗口(Window)来处理用户的交互操作,例如编辑、查看或确认等。本话题主要关注如何在EXTJS3的Window组件中实现一个功能:当用户在窗口内修改了数据后,关闭窗口时...
总结起来,EXTJS中实现Window的最小化和还原功能需要对EXTJS组件系统有深入理解,包括Window组件的属性和方法,以及事件驱动的编程模式。通过自定义事件处理和状态管理,我们可以为EXTJS应用添加这样的高级交互功能...
7. statusbar - xtype: 'statusbar', 描述: 状态条(2.2 加进来,3.0 又去了) 颜色 Palette 1. colorpalette - xtype: 'colorpalette', 描述: 调色板 日期选择器 1. datepicker - xtype: 'datepicker', 描述: ...
首先,我们要理解表单(Form)在ExtJS中的基本概念。表单是数据输入和验证的核心组件,可以包含各种字段类型,如文本框、下拉菜单、复选框等。这些字段可以通过`Ext.form.field.Field`基类进行扩展,每个字段都有其...
### ExtJs Grid 多选及获取选中值详解 #### 一、背景介绍 在Web应用开发中,ExtJs 是一款非常强大的JavaScript框架,它能够帮助开发者快速构建复杂的用户界面。其中,Grid Panel(简称 Grid)是ExtJs中最常用的一个...
### extjs-form组件配置参数详解 #### 一、Ext.form.Action `Ext.form.Action`是ExtJS中的一个类,用于处理表单提交和加载数据的动作。它提供了多种配置选项和属性来控制表单操作的过程。 **配置项** - **success*...
extjs4 grid 包括form js代码
【spritemaker_extjs:带有 extjs ui 的 css sprite maker】是一个专为 ExtJS 用户界面设计的 CSS Sprite 生成工具。这个工具可以帮助开发者合并多个小图(图标或UI元素)成一个大图(Sprite 图),以此优化网页加载...
ExtJS Grid是一个强大的数据展示组件,它允许用户以表格的形式查看和操作大量数据。在实际应用中,数据过滤是常见的需求,以便用户能快速定位到感兴趣的信息。本篇将深入探讨ExtJS Grid的过滤操作,以及如何动态地对...
ExtJS 是一个强大的JavaScript 框架,专用于构建富客户端Web应用程序。它提供了一整套组件化的用户界面元素,包括表单(Form)、网格(Grid)、树形视图(Tree)等,使得开发者能够创建出功能丰富且交互性强的前端...
主要用例子说明extjs4的form表单的运用,其中有表单属性说明,表单控件运用说明如: title:'表单', //表单标题 bodyStyle:'padding:5 5 5 5', //表单边距 height:120, //表单高度 width:200, //表单宽度 ...
第二十四讲: EXTJS4.0的高级组件Form补充01 第二十五讲: EXTJS4.0的高级组件Form补充02 第二十六讲: EXTJS4.0的高级组件Panel和Layout上 第二十七讲: EXTJS4.0的高级组件Panel和Layout下 第二十八讲: EXTJS4.0的高级...
在 ExtJS4 中,API 也发生了很大的变化,包括 tree、tab panel、grid、window、form、chart、data stores、border layout 等等。这些变化使得大型应用程序迁移变得非常困难。 在 ExtJS3 中,我们可以使用 Ext....
eslint-plugin-extjs 使用ExtJS框架的项目的ESLint规则。 这些规则的目标是与ExtJS 4.x一起使用。 欢迎请求与5.x兼容的请求! 规则明细 ext-array-foreach ExtJS提供的两个主要的数组迭代器函数和不同之处在于, ...
1. **异步提交**:使用ExtJS的`form.submit`方法,可以实现Ajax方式的表单提交,无需刷新整个页面。 2. **处理响应**:Struts2将返回JSON或XML格式的结果,ExtJS可以解析这些响应,根据返回的状态(成功或失败)更新...
Alien::Web::ExtJS::V3 - ExtJS 3.x 源的 Perl 发行版 版本 ExtJS v3.4.11 (GPL) 概要 use Alien::Web::ExtJS::V3 '3.4.11'; my $dir = Alien::Web::ExtJS::V3->dir; print "ExtJS sources are installed in: $dir\...
第二十五讲:extjs4.0的高级组件form补充02 第二十六讲:extjs4.0的高级组件panel和layout上 第二十七讲:extjs4.0的高级组件panel和layout下 第二十八讲:extjs4.0的高级组件chart上 第二十九讲:extjs4.0的...