3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file. Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
18 'Ext.tip.QuickTipManager'
21 Ext.onReady(function() {
22 Ext.tip.QuickTipManager.init();
24 var formPanel = Ext.widget('form', {
25 renderTo: Ext.getBody(),
30 title: 'Account Registration',
38 invalidCls: '' //unset the invalidCls so individual fields do not get styled as invalid
42 * Listen for validity change on the entire form and update the combined error icon
45 fieldvaliditychange: function() {
46 this.updateErrorState();
48 fielderrorchange: function() {
49 this.updateErrorState();
53 updateErrorState: function() {
55 errorCmp, fields, errors;
57 if (me.hasBeenDirty || me.getForm().isDirty()) { //prevents showing global error when form first loads
58 errorCmp = me.down('#formErrorState');
59 fields = me.getForm().getFields();
61 fields.each(function(field) {
62 Ext.Array.forEach(field.getErrors(), function(error) {
63 errors.push({name: field.getFieldLabel(), error: error});
66 errorCmp.setErrors(errors);
67 me.hasBeenDirty = true;
74 fieldLabel: 'User Name',
80 fieldLabel: 'Email Address',
86 fieldLabel: 'Password',
87 inputType: 'password',
88 style: 'margin-top:15px',
94 fieldLabel: 'Repeat Password',
95 inputType: 'password',
98 * Custom validator implementation - checks that the value matches what was entered into
99 * the password1 field.
101 validator: function(value) {
102 var password1 = this.previousSibling('[name=password1]');
103 return (value === password1.getValue()) ? true : 'Passwords do not match.'
108 * Terms of Use acceptance checkbox. Two things are special about this:
109 * 1) The boxLabel contains a HTML link to the Terms of Use page; a special click listener opens this
110 * page in a modal Ext window for convenient viewing, and the Decline and Accept buttons in the window
111 * update the checkbox's state automatically.
112 * 2) This checkbox is required, i.e. the form will not be able to be submitted unless the user has
113 * checked the box. Ext does not have this type of validation built in for checkboxes, so we add a
114 * custom getErrors method implementation.
117 xtype: 'checkboxfield',
119 fieldLabel: 'Terms of Use',
121 style: 'margin-top:15px',
122 boxLabel: 'I have read and accept the <a href="http://www.sencha.com/legal/terms-of-use/" class="terms">Terms of Use</a>.',
124 // Listener to open the Terms of Use page link in a modal window
127 element: 'boxLabelEl',
129 var target = e.getTarget('.terms'),
132 win = Ext.widget('window', {
133 title: 'Terms of Use',
135 html: '<iframe src="' + target.href + '" width="950" height="500" style="border:0"></iframe>',
138 handler: function() {
139 this.up('window').close();
140 formPanel.down('[name=acceptTerms]').setValue(false);
144 handler: function() {
145 this.up('window').close();
146 formPanel.down('[name=acceptTerms]').setValue(true);
157 // Custom validation logic - requires the checkbox to be checked
158 getErrors: function() {
159 return this.getValue() ? [] : ['You must accept the Terms of Use']
174 id: 'formErrorState',
175 baseCls: 'form-error-state',
177 validText: 'Form is valid',
178 invalidText: 'Form has errors',
179 tipTpl: Ext.create('Ext.XTemplate', '<ul><tpl for="."><li><span class="field-name">{name}</span>: <span class="error">{error}</span></li></tpl></ul>'),
184 tip = this.tip = Ext.widget('tooltip', {
186 title: 'Error Details:',
189 mouseOffset: [-11, -2],
191 constrainPosition: false,
199 setErrors: function(errors) {
201 baseCls = me.baseCls,
204 errors = Ext.Array.from(errors);
206 // Update CSS class and tooltip content
208 me.addCls(baseCls + '-invalid');
209 me.removeCls(baseCls + '-valid');
210 me.update(me.invalidText);
211 tip.setDisabled(false);
212 tip.update(me.tipTpl.apply(errors));
214 me.addCls(baseCls + '-valid');
215 me.removeCls(baseCls + '-invalid');
216 me.update(me.validText);
217 tip.setDisabled(true);
225 text: 'Submit Registration',
227 handler: function() {
228 var form = this.up('form').getForm();
230 /* Normally we would submit the form to the server here and handle the response...
232 clientValidation: true,
234 success: function(form, action) {
237 failure: function(form, action) {
243 if (form.isValid()) {
244 Ext.Msg.alert('Submitted Values', form.getValues(true));