dojo: Set ValidationTextBox to blur

2019-08-04 10:56发布

问题:

I can't make ValidationTextBox to lose focus and I can't see the method blur() either.

How can I make it lose focus?

回答1:

The blur() method works on dom nodes. A widget is often backed by an html template. If you look at dijit/form/templates/ValidationTextBox.html, you will see that there is a dom node which has a dojoAttachPoint containing "focusNode". Here is the code of the template on dojo 1.7, for reference :

<div class="dijit dijitReset dijitInlineTable dijitLeft"
id="widget_${id}" role="presentation"
><div class='dijitReset dijitValidationContainer'
    ><input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" value="&#935; " type="text" tabIndex="-1" readonly="readonly" role="presentation"
/></div
><div class="dijitReset dijitInputField dijitInputContainer"
    ><input class="dijitReset dijitInputInner" dojoAttachPoint='textbox,focusNode' autocomplete="off"
        ${!nameAttrSetting} type='${type}'
/></div

You can achieve your blur trigger through a direct reference of the node referenced in the template as "focusNode" by doing something like :

dijit.byId("myValidationTextBoxId").focusNode.blur();


回答2:

You have to override the functionality of the class ValidationtextBox.js. By default its is always invoked on the onkeypress event.



标签: dojo