_ValueMixin.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. define("dojox/form/manager/_ValueMixin", [
  2. "dojo/_base/lang",
  3. "dojo/_base/kernel",
  4. "dojo/_base/declare"
  5. ], function(lang, dojo, declare){
  6. return declare("dojox.form.manager._ValueMixin", null, {
  7. // summary:
  8. // Form manager's mixin for getting/setting form values in the unified manner.
  9. // description:
  10. // This mixin adds unified access to form widgets and form elements
  11. // in terms of name-value regardless of the underlying type of
  12. // an element. It should be used together with dojox.form.manager.Mixin.
  13. elementValue: function(name, value){
  14. // summary:
  15. // Set or get a form widget/element or an attached point node by name.
  16. // name: String:
  17. // The name.
  18. // value: Object?:
  19. // Optional. The value to set.
  20. if(name in this.formWidgets){
  21. return this.formWidgetValue(name, value); // Object
  22. }
  23. if(this.formNodes && name in this.formNodes){
  24. return this.formNodeValue(name, value); // Object
  25. }
  26. return this.formPointValue(name, value); // Object
  27. },
  28. gatherFormValues: function(names){
  29. // summary:
  30. // Collect form values.
  31. // names: Object?:
  32. // If it is an array, it is a list of names of form elements to be collected.
  33. // If it is an object, dictionary keys are names to be collected.
  34. // If it is omitted, all known form elements are to be collected.
  35. var result = this.inspectFormWidgets(function(name){
  36. return this.formWidgetValue(name);
  37. }, names);
  38. if(this.inspectFormNodes){
  39. lang.mixin(result, this.inspectFormNodes(function(name){
  40. return this.formNodeValue(name);
  41. }, names));
  42. }
  43. lang.mixin(result, this.inspectAttachedPoints(function(name){
  44. return this.formPointValue(name);
  45. }, names));
  46. return result; // Object
  47. },
  48. setFormValues: function(values){
  49. // summary:
  50. // Set values to form elements
  51. // values: Object:
  52. // A dictionary of key-value pairs.
  53. if(values){
  54. this.inspectFormWidgets(function(name, widget, value){
  55. this.formWidgetValue(name, value);
  56. }, values);
  57. if(this.inspectFormNodes){
  58. this.inspectFormNodes(function(name, node, value){
  59. this.formNodeValue(name, value);
  60. }, values);
  61. }
  62. this.inspectAttachedPoints(function(name, node, value){
  63. this.formPointValue(name, value);
  64. }, values);
  65. }
  66. return this;
  67. }
  68. });
  69. });