JSFiddle - React, Tailwind, and code Playground
For SO question http://stackoverflow.com/questions/4662646/dojo-dojo-onblur-events
HTML
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css">
Vehicle:
<input dojoType="dijit.form.ComboBox"
store="xvarStore"
value=""
searchAttr="name"
name="vehicle_1"
id="vehicle_1"
onBlur="isValid"
/>
Descriptor:
<input type="text"
dojoType="dijit.form.TextBox"
value=""
class=lighttext
style="width:350px;height:19px"
id="filter_value_1"
name="filter_value_1"
onBlur="isValid"
/>
Vehicle:
<input dojoType="dijit.form.ComboBox"
store="xvarStore"
value=""
searchAttr="name"
name="vehicle_2"
id="vehicle_2"
onBlur="isValid"
/>
Descriptor:
<textarea
dojoType="dijit.form.Textarea"
id="filter_value_2"
name="filter_value_2"
onChange="isValid"
></textarea>
JavaScript
dojo.require('dijit.form.TextBox');
dojo.require('dijit.form.Textarea');
dojo.require('dijit.form.ComboBox');
dojo.require('dojo.parser');
dojo.require('dojo.data.ItemFileReadStore');
var xvarStore;
function isValid() {
var
//grab number off end of id of widget event fired on
//(this method is normally called in the context of the blurred widget)
/* num = this.id.match(/_(\d+)$/)[1],
//grab both associated widgets based on that number
tb = dijit.byId('vehicle_' + num),
cb = dijit.byId('filter_value_' + num),
ret;*/
dd = dijit.byId("filter_value_2").value;
if(dd.lenght>2){
dijit.byId("filter_value_2").value = dd.substring(0,2);
}
//bail out if we somehow failed to find one or the other
/* if (!tb || !cb) {
return false;
}
//fields are valid if either both are filled or both are empty.
//shortcut: boolean-negating both will coerce both to boolean,
//for an easy comparison to each other.
ret = ( !tb.get('value') == !cb.get('value'));
console.log(num, ' valid? ', ret);*/
console.log(dd);
return dd;
}
dojo.ready(function() {
xvarStore = new dojo.data.ItemFileReadStore({
data: {
identifier: 'id',
items: [
{
id: 'R',
name: 'red'},
{
id: 'B',
name: 'blue'},
{
id: 'P',
name: 'plaid'}
]
}
});
dojo.parser.parse();
});