1 /*jshint node:true, indent:2, curly:true, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
2 regexp:true, undef:true, trailing:true, white:true */
3 /*global XT:true, XV:true, Globalize:true, enyo:true, _:true */
9 @class Maintains a consistent API to be used by workspaces.<br />
10 The superkind from which other xTuple input objects are derived.<br />
11 To create an input field for strings, see {@link XV.InputWidget}.<br />
12 To create an input field for dates, see {@link XV.DateWidget}.<br />
13 To create an input field for files, see {@link XV.FileInput}.<br />
14 To create an input field for numbers, see {@link XV.NumberWidget}.<br />
15 To create a multi-line textarea input box, see {@link XV.TextArea}.<br />
16 To create a checkbox, see {@link XV.CheckboxWidget}.<br />
17 To create a togglebutton, see {@link XV.TogglebuttonWidget}.<br />
20 /** @lends XV.InputWidget# */{
21 name: "XV.InputWidget",
40 {kind: "FittableColumns", components: [
41 {name: "label", content: "", fit: true, classes: "xv-flexible-label"},
42 {kind: "onyx.InputDecorator", classes: "xv-input-decorator",
44 {name: "input", kind: "onyx.Input", classes: "xv-subinput",
45 onchange: "inputChanged", onkeydown: "keyDown"}
50 this.inherited(arguments);
51 this.placeholderChanged();
52 this.disabledChanged();
54 this.maxlengthChanged();
56 this.showLabelChanged();
59 Sets the value of the input to an empty string
61 clear: function (options) {
62 this.setValue("", options);
65 The disabledChanged method, and many below it, are here to deal with
66 the fact that XV.Input doesvnot inherit from onyx.input or enyo.input,
67 and so insofar as it needs to support their APIs, we
68 have to redeclare the methods and pass through the data.
70 disabledChanged: function () {
71 this.$.input.setDisabled(this.getDisabled());
77 Called when the user changes the input. Validates field.
78 If valid, calls setValue, which bubbles the event. Otherwise
79 we bubble ourselves the empty string.
81 inputChanged: function (inSender, inEvent) {
82 var input = this.$.input.getValue(),
83 value = this.validate(input);
84 if (value !== false) {
85 // is valid and not empty
88 // is invalid or empty
93 "text-shadow-none" hack here to fix issue #18397
94 @todo Revisit/remove after fix to ENYO-1104. See also issue 18397.
96 Added some handling here to force the input to save the value when
97 the user uses the arrows or tab key.
99 keyDown: function (inSender, inEvent) {
100 var shadowNone = inEvent.originator.hasClass("text-shadow-none"),
101 keyCode = inEvent.keyCode;
103 inEvent.originator.addRemoveClass("text-shadow-none", !shadowNone);
104 inEvent.originator.addRemoveClass("text-shadow-0", shadowNone);
106 // this adds support for tabbing and arrowing through grids
107 if (keyCode === XV.KEY_TAB || keyCode === XV.KEY_DOWN || keyCode === XV.KEY_UP) {
112 @todo Document the placeholderChanged method.
114 placeholderChanged: function () {
115 var placeholder = this.getPlaceholder();
116 this.$.input.setPlaceholder(placeholder);
119 Webkit browsers do not always emit the proper change event,
120 so this ensures that the changed value is saved.
122 receiveBlur: function () {
123 if (this.$.input.getValue() !== this.getValue()) {
128 If the value has changed, update the user field using valueChanged,
129 and bubble up the event so that the model may be updated (unless
130 silent is true, which is how the workspace invokes it). This
131 function nicely handles being told what to do both from below, by
132 the user, or from above, by the workspace. The event
133 that it bubbles up is valueChange, whereas the event that probably
134 triggered it is inputChange.
136 setValue: function (value, options) {
137 options = options || {};
138 var oldValue = this.getValue(),
140 if (oldValue !== value) {
142 this.valueChanged(value);
143 if (!options.silent) {
144 inEvent = { value: value, originator: this };
145 // this bubbles up the onValueChange event which then
146 // triggers the controlValueChanged in the workspace
147 this.doValueChange(inEvent);
152 Returns the value if it's valid, or false if it's not
154 validate: function (value) {
158 Updates the field that the user sees based on the published field.
160 valueChanged: function (value) {
161 this.$.input.setValue(value || "");
165 Pass through attributes intended for onyx input inside.
167 setInputStyle: function (style) {
168 this.$.input.setStyle(style);
171 Pass through attributes intended for onyx input inside.
173 typeChanged: function () {
174 this.$.input.setType(this.getType());
177 maxlengthChanged: function () {
178 this.$.input.setAttribute("maxlength", this.maxlength);
182 Sets the label content based on the label value or the attribute text.
184 labelChanged: function () {
185 var label = (this.getLabel() || ("_" + this.attr || "").loc());
186 this.$.label.setContent(label + ":");
190 @todo Document the showLabelChanged method.
192 showLabelChanged: function () {
193 if (this.getShowLabel()) {