summaryrefslogtreecommitdiff
path: root/js/dojo-1.7.2/dojox/form/manager/_ValueMixin.js
blob: 785a15faaf000a69260a289af64a546925f9781a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//>>built
define("dojox/form/manager/_ValueMixin", [
	"dojo/_base/lang",
	"dojo/_base/kernel",
	"dojo/_base/declare"
], function(lang, dojo, declare){
return declare("dojox.form.manager._ValueMixin", null, {
	// summary:
	//		Form manager's mixin for getting/setting form values in the unified manner.
	// description:
	//		This mixin adds unified access to form widgets and form elements
	//		in terms of name-value regardless of the underlying type of
	//		an element. It should be used together with dojox.form.manager.Mixin.

	elementValue: function(name, value){
		// summary:
		//		Set or get a form widget/element or an attached point node by name.
		// name: String:
		//		The name.
		// value: Object?:
		//		Optional. The value to set.

		if(name in this.formWidgets){
			return this.formWidgetValue(name, value);	// Object
		}

		if(this.formNodes && name in this.formNodes){
			return this.formNodeValue(name, value);	// Object
		}

		return this.formPointValue(name, value);	// Object
	},

	gatherFormValues: function(names){
		// summary:
		//		Collect form values.
		// names: Object?:
		//		If it is an array, it is a list of names of form elements to be collected.
		//		If it is an object, dictionary keys are names to be collected.
		//		If it is omitted, all known form elements are to be collected.

		var result = this.inspectFormWidgets(function(name){
			return this.formWidgetValue(name);
		}, names);

		if(this.inspectFormNodes){
			lang.mixin(result, this.inspectFormNodes(function(name){
				return this.formNodeValue(name);
			}, names));
		}

		lang.mixin(result, this.inspectAttachedPoints(function(name){
			return this.formPointValue(name);
		}, names));

		return result;	// Object
	},

	setFormValues: function(values){
		// summary:
		//		Set values to form elements
		// values: Object:
		//		A dictionary of key-value pairs.
		if(values){
			this.inspectFormWidgets(function(name, widget, value){
				this.formWidgetValue(name, value);
			}, values);

			if(this.inspectFormNodes){
				this.inspectFormNodes(function(name, node, value){
					this.formNodeValue(name, value);
				}, values);
			}

			this.inspectAttachedPoints(function(name, node, value){
				this.formPointValue(name, value);
			}, values);
		}
		return this;
	}
});
});