1
|
define([
|
2
|
'dojo/_base/declare',
|
3
|
'dijit/form/TextBox'
|
4
|
], function(declare, TextBox){
|
5
|
|
6
|
var ClearTextBox = declare('stabile.ClearTextBox', TextBox, {
|
7
|
|
8
|
// The "Delete" word
|
9
|
deleteText: "",
|
10
|
|
11
|
// Fire the change event for every text change
|
12
|
intermediateChanges: true,
|
13
|
|
14
|
// PostCreate method
|
15
|
// Fires *after* nodes are created, before rendered to screen
|
16
|
postCreate: function() {
|
17
|
// Do what the previous does with this method
|
18
|
this.inherited(arguments);
|
19
|
|
20
|
// Add widget class to the domNode
|
21
|
var domNode = this.domNode;
|
22
|
dojo.addClass(domNode, "stabileClearBox");
|
23
|
|
24
|
// Create the "X" link
|
25
|
this.clearLink = dojo.create("a", {
|
26
|
className: "stabileClear",
|
27
|
innerHTML: this.deleteText
|
28
|
}, domNode, "first");
|
29
|
|
30
|
// Fix the width
|
31
|
var startWidth = dojo.style(domNode, "width"),
|
32
|
pad = dojo.style(this.domNode,"paddingRight");
|
33
|
dojo.style(domNode, "width", (startWidth - pad) + "px");
|
34
|
|
35
|
// Add click event to focus node
|
36
|
this.connect(this.clearLink, "onclick", function(){
|
37
|
// Clear the value
|
38
|
this.set("value", "");
|
39
|
// Focus on the node, not the link
|
40
|
this.textbox.blur();
|
41
|
});
|
42
|
|
43
|
// Add intermediate change for self so that "X" hides when no value
|
44
|
this.connect(this, "onChange", "checkValue");
|
45
|
|
46
|
// Check value right away, hide link if necessary
|
47
|
this.checkValue();
|
48
|
},
|
49
|
|
50
|
checkValue: function(value) {
|
51
|
dojo[(value != "" && value != undefined ? "remove" : "add") + "Class"](this.clearLink, "dijitHidden");
|
52
|
}
|
53
|
});
|
54
|
|
55
|
});
|