MappedTextBox.js.uncompressed.js 3.0 KB

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