MappedTextBox.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. define("dijit/form/MappedTextBox", [
  2. "dojo/_base/declare", // declare
  3. "dojo/dom-construct", // domConstruct.place
  4. "./ValidationTextBox"
  5. ], function(declare, domConstruct, ValidationTextBox){
  6. /*=====
  7. var ValidationTextBox = dijit.form.ValidationTextBox;
  8. =====*/
  9. // module:
  10. // dijit/form/MappedTextBox
  11. // summary:
  12. // A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
  13. // a visible formatted display value, and a serializable
  14. // value in a hidden input field which is actually sent to the server.
  15. return declare("dijit.form.MappedTextBox", ValidationTextBox, {
  16. // summary:
  17. // A dijit.form.ValidationTextBox subclass which provides a base class for widgets that have
  18. // a visible formatted display value, and a serializable
  19. // value in a hidden input field which is actually sent to the server.
  20. // description:
  21. // The visible display may
  22. // be locale-dependent and interactive. The value sent to the server is stored in a hidden
  23. // input field which uses the `name` attribute declared by the original widget. That value sent
  24. // to the server is defined by the dijit.form.MappedTextBox.serialize method and is typically
  25. // locale-neutral.
  26. // tags:
  27. // protected
  28. postMixInProperties: function(){
  29. this.inherited(arguments);
  30. // we want the name attribute to go to the hidden <input>, not the displayed <input>,
  31. // so override _FormWidget.postMixInProperties() setting of nameAttrSetting
  32. this.nameAttrSetting = "";
  33. },
  34. // Override default behavior to assign name to focusNode
  35. _setNameAttr: null,
  36. serialize: function(val /*=====, options =====*/){
  37. // summary:
  38. // Overridable function used to convert the get('value') result to a canonical
  39. // (non-localized) string. For example, will print dates in ISO format, and
  40. // numbers the same way as they are represented in javascript.
  41. // val: anything
  42. // options: Object?
  43. // tags:
  44. // protected extension
  45. return val.toString ? val.toString() : ""; // String
  46. },
  47. toString: function(){
  48. // summary:
  49. // Returns widget as a printable string using the widget's value
  50. // tags:
  51. // protected
  52. var val = this.filter(this.get('value')); // call filter in case value is nonstring and filter has been customized
  53. return val != null ? (typeof val == "string" ? val : this.serialize(val, this.constraints)) : ""; // String
  54. },
  55. validate: function(){
  56. // Overrides `dijit.form.TextBox.validate`
  57. this.valueNode.value = this.toString();
  58. return this.inherited(arguments);
  59. },
  60. buildRendering: function(){
  61. // Overrides `dijit._TemplatedMixin.buildRendering`
  62. this.inherited(arguments);
  63. // Create a hidden <input> node with the serialized value used for submit
  64. // (as opposed to the displayed value).
  65. // Passing in name as markup rather than calling domConstruct.create() with an attrs argument
  66. // to make query(input[name=...]) work on IE. (see #8660)
  67. this.valueNode = domConstruct.place("<input type='hidden'" + (this.name ? " name='" + this.name.replace(/'/g, "&quot;") + "'" : "") + "/>", this.textbox, "after");
  68. },
  69. reset: function(){
  70. // Overrides `dijit.form.ValidationTextBox.reset` to
  71. // reset the hidden textbox value to ''
  72. this.valueNode.value = '';
  73. this.inherited(arguments);
  74. }
  75. });
  76. });