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