4 'Ext.tip.QuickTipManager'
7 Ext.onReady(function() {
8 Ext.tip.QuickTipManager.init();
10 var formPanel = Ext.widget('form', {
11 renderTo: Ext.getBody(),
16 title: 'Account Registration',
24 invalidCls: '' //unset the invalidCls so individual fields do not get styled as invalid
28 * Listen for validity change on the entire form and update the combined error icon
31 fieldvaliditychange: function() {
32 this.updateErrorState();
34 fielderrorchange: function() {
35 this.updateErrorState();
39 updateErrorState: function() {
41 errorCmp, fields, errors;
43 if (me.hasBeenDirty || me.getForm().isDirty()) { //prevents showing global error when form first loads
44 errorCmp = me.down('#formErrorState');
45 fields = me.getForm().getFields();
47 fields.each(function(field) {
48 Ext.Array.forEach(field.getErrors(), function(error) {
49 errors.push({name: field.getFieldLabel(), error: error});
52 errorCmp.setErrors(errors);
53 me.hasBeenDirty = true;
60 fieldLabel: 'User Name',
66 fieldLabel: 'Email Address',
72 fieldLabel: 'Password',
73 inputType: 'password',
74 style: 'margin-top:15px',
80 fieldLabel: 'Repeat Password',
81 inputType: 'password',
84 * Custom validator implementation - checks that the value matches what was entered into
85 * the password1 field.
87 validator: function(value) {
88 var password1 = this.previousSibling('[name=password1]');
89 return (value === password1.getValue()) ? true : 'Passwords do not match.'
94 * Terms of Use acceptance checkbox. Two things are special about this:
95 * 1) The boxLabel contains a HTML link to the Terms of Use page; a special click listener opens this
96 * page in a modal Ext window for convenient viewing, and the Decline and Accept buttons in the window
97 * update the checkbox's state automatically.
98 * 2) This checkbox is required, i.e. the form will not be able to be submitted unless the user has
99 * checked the box. Ext does not have this type of validation built in for checkboxes, so we add a
100 * custom getErrors method implementation.
103 xtype: 'checkboxfield',
105 fieldLabel: 'Terms of Use',
107 style: 'margin-top:15px',
108 boxLabel: 'I have read and accept the <a href="http://www.sencha.com/legal/terms-of-use/" class="terms">Terms of Use</a>.',
110 // Listener to open the Terms of Use page link in a modal window
113 element: 'boxLabelEl',
115 var target = e.getTarget('.terms'),
118 win = Ext.widget('window', {
119 title: 'Terms of Use',
121 html: '<iframe src="' + target.href + '" width="950" height="500" style="border:0"></iframe>',
124 handler: function() {
125 this.up('window').close();
126 formPanel.down('[name=acceptTerms]').setValue(false);
130 handler: function() {
131 this.up('window').close();
132 formPanel.down('[name=acceptTerms]').setValue(true);
143 // Custom validation logic - requires the checkbox to be checked
144 getErrors: function() {
145 return this.getValue() ? [] : ['You must accept the Terms of Use']
160 id: 'formErrorState',
161 baseCls: 'form-error-state',
163 validText: 'Form is valid',
164 invalidText: 'Form has errors',
165 tipTpl: Ext.create('Ext.XTemplate', '<ul><tpl for="."><li><span class="field-name">{name}</span>: <span class="error">{error}</span></li></tpl></ul>'),
170 tip = this.tip = Ext.widget('tooltip', {
172 title: 'Error Details:',
175 mouseOffset: [-11, -2],
177 constrainPosition: false,
185 setErrors: function(errors) {
187 baseCls = me.baseCls,
190 errors = Ext.Array.from(errors);
192 // Update CSS class and tooltip content
194 me.addCls(baseCls + '-invalid');
195 me.removeCls(baseCls + '-valid');
196 me.update(me.invalidText);
197 tip.setDisabled(false);
198 tip.update(me.tipTpl.apply(errors));
200 me.addCls(baseCls + '-valid');
201 me.removeCls(baseCls + '-invalid');
202 me.update(me.validText);
203 tip.setDisabled(true);
211 text: 'Submit Registration',
213 handler: function() {
214 var form = this.up('form').getForm();
216 /* Normally we would submit the form to the server here and handle the response...
218 clientValidation: true,
220 success: function(form, action) {
223 failure: function(form, action) {
229 if (form.isValid()) {
230 Ext.Msg.alert('Submitted Values', form.getValues(true));