×
Creating solutions

Ako zakázať onChange pri nastavení hodnoty widgetu

Asi málokto vie, že metóda set() podporuje aj ďalšie argumenty ako property a value cez zápis widget.set(property, value). Jedným z nich je aj argument s interným názvom priorityChange, ktorý zabraňuje spusteniu eventu onChange.
Vďaka argumentu priorityChange je možné vykonať zápis widget.set(property, value, priorityChange). O spracovanie argumentu priorityChange sa stará modul _WidgetBase.js. V tomto kroku je ostránený argument property, resp. name a posúvajú sa už len argumenty value, priorityChange a formattedValue.
Príklad: Zápis, ktorý aplikuje priorityChange.
1
var result = setter.apply(this, Array.prototype.slice.call(arguments, 1));
Teraz, keď som už popísal proces spracovania argumentov pri metóde set() vo widgete TextBox, uvediem aj príklad pre odskúšanie argumentu priorityChange.
Príklad: Zápis do elementu <body>.
1
2
3
4
<div id="textbox"></div>
<div id="button" data-dojo-type="dijit/form/Button">onChange enabled</div>
<div id="button1" data-dojo-type="dijit/form/Button">onChange enabled</div>
<div id="button2" data-dojo-type="dijit/form/Button">onChange disabled</div>
Príklad: Zápis do elementu <script>.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
new TextBox({
id: "textBox",
name: "select-control",
onChange: function () {
console.log("onChange");
}
}, "textbox");
var button = registry.byId("button");
button.onClick = function () {
var textBox = registry.byId("textBox");
textBox.set("value", "test");
}
var button1 = registry.byId("button1");
button1.onClick = function () {
var textBox = registry.byId("textBox");
textBox.set("value", "test1", true);
}
var button2 = registry.byId("button2");
button2.onClick = function () {
var textBox = registry.byId("textBox");
textBox.set("value", "test2", false);
}
Prvý set je štandardný, druhý a tretí je s použitím argumentu priorityChange. Tretí zabraňuje spusteniu eventu onChange.

Záver

Widget TextBox podporuje v metóde _setValueAttr() aj ďalší argument s názvom formattedValue.
Príklad: Definícia metódy _setValueAttr() v súbore TextBox.js.
1
2
3
4
function(value, /*Boolean?*/ priorityChange, /*String?*/ formattedValue){
this.inherited(arguments);
this._updatePlaceHolder();
}


Dojo,dijit/form/TextBox,dijit/registry,set(),onChange,onClick
No part of this article may be reproduced without mention of the author and URL to this website.
For more information, see the About section.

Comments

Article has no comments.

Add a comment

Name (required)
Website
Message (required)
Submit
From latest