_ValueMixin.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dojox.form.manager._ValueMixin"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dojox.form.manager._ValueMixin"] = true;
  8. dojo.provide("dojox.form.manager._ValueMixin");
  9. dojo.declare("dojox.form.manager._ValueMixin", null, {
  10. // summary:
  11. // Form manager's mixin for getting/setting form values in the unified manner.
  12. // description:
  13. // This mixin adds unified access to form widgets and form elements
  14. // in terms of name-value regardless of the underlying type of
  15. // an element. It should be used together with dojox.form.manager.Mixin.
  16. elementValue: function(name, value){
  17. // summary:
  18. // Set or get a form widget/element or an attached point node by name.
  19. // name: String:
  20. // The name.
  21. // value: Object?:
  22. // Optional. The value to set.
  23. if(name in this.formWidgets){
  24. return this.formWidgetValue(name, value); // Object
  25. }
  26. if(this.formNodes && name in this.formNodes){
  27. return this.formNodeValue(name, value); // Object
  28. }
  29. return this.formPointValue(name, value); // Object
  30. },
  31. gatherFormValues: function(names){
  32. // summary:
  33. // Collect form values.
  34. // names: Object?:
  35. // If it is an array, it is a list of names of form elements to be collected.
  36. // If it is an object, dictionary keys are names to be collected.
  37. // If it is omitted, all known form elements are to be collected.
  38. var result = this.inspectFormWidgets(function(name){
  39. return this.formWidgetValue(name);
  40. }, names);
  41. if(this.inspectFormNodes){
  42. dojo.mixin(result, this.inspectFormNodes(function(name){
  43. return this.formNodeValue(name);
  44. }, names));
  45. }
  46. dojo.mixin(result, this.inspectAttachedPoints(function(name){
  47. return this.formPointValue(name);
  48. }, names));
  49. return result; // Object
  50. },
  51. setFormValues: function(values){
  52. // summary:
  53. // Set values to form elements
  54. // values: Object:
  55. // A dictionary of key-value pairs.
  56. if(values){
  57. this.inspectFormWidgets(function(name, widget, value){
  58. this.formWidgetValue(name, value);
  59. }, values);
  60. if(this.inspectFormNodes){
  61. this.inspectFormNodes(function(name, node, value){
  62. this.formNodeValue(name, value);
  63. }, values);
  64. }
  65. this.inspectAttachedPoints(function(name, node, value){
  66. this.formPointValue(name, value);
  67. }, values);
  68. }
  69. return this;
  70. }
  71. });
  72. }