]>
Commit | Line | Data |
---|---|---|
6527f429 DM |
1 | Ext.define('KitchenSink.view.form.CustomErrorHandlingController', {\r |
2 | extend: 'Ext.app.ViewController',\r | |
3 | alias: 'controller.form-customerrors',\r | |
4 | \r | |
5 | submitRegistration: function() {\r | |
6 | var form = this.getView().getForm();\r | |
7 | \r | |
8 | /* Normally we would submit the form to the server here and handle the response...\r | |
9 | form.submit({\r | |
10 | clientValidation: true,\r | |
11 | url: 'register.php',\r | |
12 | success: function(form, action) {\r | |
13 | //...\r | |
14 | },\r | |
15 | failure: function(form, action) {\r | |
16 | //...\r | |
17 | }\r | |
18 | });\r | |
19 | */\r | |
20 | \r | |
21 | if (form.isValid()) {\r | |
22 | var out = [];\r | |
23 | Ext.Object.each(form.getValues(), function(key, value){\r | |
24 | out.push(key + '=' + value);\r | |
25 | });\r | |
26 | Ext.Msg.alert('Submitted Values', out.join('<br />'));\r | |
27 | }\r | |
28 | },\r | |
29 | \r | |
30 | updateErrorState: function(cmp, state) {\r | |
31 | var me = this,\r | |
32 | errorCmp = me.lookupReference('formErrorState'),\r | |
33 | view, form, fields, errors;\r | |
34 | \r | |
35 | view = me.getView();\r | |
36 | form = view.getForm();\r | |
37 | \r | |
38 | // If we are called from the form's validitychange event, the state will be false if invalid.\r | |
39 | // If we are called from a field's errorchange event, the state will be the error message.\r | |
40 | if (state === false || (typeof state === 'string')) {\r | |
41 | fields = form.getFields();\r | |
42 | errors = [];\r | |
43 | \r | |
44 | fields.each(function(field) {\r | |
45 | Ext.Array.forEach(field.getErrors(), function(error) {\r | |
46 | errors.push({name: field.getFieldLabel(), error: error});\r | |
47 | });\r | |
48 | });\r | |
49 | \r | |
50 | errorCmp.setErrors(errors);\r | |
51 | me.hasBeenDirty = true;\r | |
52 | } else if (state === true) {\r | |
53 | errorCmp.setErrors();\r | |
54 | }\r | |
55 | },\r | |
56 | \r | |
57 | onTermsOfUseElementClick: function(e) {\r | |
58 | var target;\r | |
59 | \r | |
60 | target = e.getTarget('.terms');\r | |
61 | e.preventDefault();\r | |
62 | \r | |
63 | if (target) {\r | |
64 | this.lookupReference('termsOfUseWindow').show();\r | |
65 | }\r | |
66 | },\r | |
67 | \r | |
68 | acceptTermsOfUse: function() {\r | |
69 | this.closeTermsOfUse(true);\r | |
70 | },\r | |
71 | \r | |
72 | declineTermsOfUse: function() {\r | |
73 | this.closeTermsOfUse(false);\r | |
74 | },\r | |
75 | \r | |
76 | closeTermsOfUse: function(accepted) {\r | |
77 | this.lookupReference('termsOfUseWindow').close();\r | |
78 | this.lookupReference('acceptTerms').setValue(accepted);\r | |
79 | }\r | |
80 | });\r |