4 'Ext.window.MessageBox'
7 Ext.onReady(function() {
11 // The data store for the State comboboxes
12 statesStore = Ext.create('Ext.data.ArrayStore', {
14 data : Ext.example.states // from states.js
17 // The data store for the Month combobox
18 monthsStore = Ext.create('Ext.data.Store', {
19 fields: ['name', 'num'],
22 Ext.Array.forEach(Ext.Date.monthNames, function(name, i) {
23 data[i] = {name: name, num: i + 1};
30 * Common change listener for the Mailing Address fields - if the checkbox to use the same
31 * values for Billing Address is checked, this copies the values over as they change.
33 function onMailingAddrFieldChange(field) {
34 var copyToBilling = formPanel.down('[name=billingSameAsMailing]').getValue();
36 formPanel.down('[name=' + field.billingFieldName + ']').setValue(field.getValue());
41 formPanel = Ext.widget('form', {
42 renderTo: Ext.getBody(),
43 title: 'Complete Check Out',
57 title: 'Your Contact Information',
58 defaultType: 'textfield',
64 xtype: 'fieldcontainer',
68 defaultType: 'textfield',
74 fieldLabel: 'First Name',
80 fieldLabel: 'Last Name',
89 defaultType: 'textfield',
91 fieldLabel: 'Email Address',
97 fieldLabel: 'Phone Number',
101 emptyText: 'xxx-xxx-xxxx',
103 regex: /^\d{3}-\d{3}-\d{4}$/,
104 regexText: 'Must be in the format xxx-xxx-xxxx'
112 title: 'Mailing Address',
113 defaultType: 'textfield',
119 fieldLabel: 'Street Address',
120 name: 'mailingStreet',
121 listeners: {change: onMailingAddrFieldChange},
122 billingFieldName: 'billingStreet',
131 listeners: {change: onMailingAddrFieldChange},
132 billingFieldName: 'billingCity',
137 name: 'mailingState',
138 listeners: {change: onMailingAddrFieldChange},
139 billingFieldName: 'billingState',
145 displayField: 'abbr',
152 fieldLabel: 'Postal Code',
154 name: 'mailingPostalCode',
155 listeners: {change: onMailingAddrFieldChange},
156 billingFieldName: 'billingPostalCode',
160 enforceMaxLength: true,
162 regex: /^\d{5}(\-\d{4})?$/,
163 regexText: 'Must be in the format xxxxx or xxxxx-xxxx'
171 title: 'Billing Address',
178 name: 'billingSameAsMailing',
179 boxLabel: 'Same as Mailing Address?',
182 style: 'margin-bottom:10px',
185 * Enables or disables the billing address fields according to whether the checkbox is checked.
186 * In addition to disabling the fields, they are animated to a low opacity so they don't take
187 * up visual attention.
189 handler: function(me, checked) {
190 var fieldset = me.ownerCt;
191 Ext.Array.forEach(fieldset.previousSibling().query('textfield'), onMailingAddrFieldChange);
192 Ext.Array.forEach(fieldset.query('textfield'), function(field) {
193 field.setDisabled(checked);
194 // Animate the opacity on each field. Would be more efficient to wrap them in a container
195 // and animate the opacity on just the single container element, but IE has a bug where
196 // the alpha filter does not get applied on position:relative children.
197 field.el.animate({opacity: checked ? .3 : 1});
202 fieldLabel: 'Street Address',
203 name: 'billingStreet',
220 name: 'billingState',
227 displayField: 'abbr',
235 fieldLabel: 'Postal Code',
237 name: 'billingPostalCode',
243 enforceMaxLength: true,
245 regex: /^\d{5}(\-\d{4})?$/,
246 regexText: 'Must be in the format xxxxx or xxxxx-xxxx'
271 inputValue: 'mastercard',
272 boxLabel: 'MasterCard'
275 boxLabel: 'American Express'
277 inputValue: 'discover',
283 fieldLabel: 'Name On Card',
291 fieldLabel: 'Card Number',
296 enforceMaxLength: true,
299 xtype: 'fieldcontainer',
300 fieldLabel: 'Expiration',
306 name: 'ccExpireMonth',
307 displayField: 'name',
318 xtype: 'numberfield',
319 name: 'ccExpireYear',
322 value: new Date().getFullYear(),
323 minValue: new Date().getFullYear(),
333 handler: function() {
334 this.up('form').getForm().reset();
337 text: 'Complete Purchase',
339 handler: function() {
340 var form = this.up('form').getForm();
341 if (form.isValid()) {
342 Ext.MessageBox.alert('Submitted Values', form.getValues(true));