How to select all value text when dijit.form.TextBox or a similar widget is focused

I am looking for a way when dijit.form.TextBox is focused or an extended / similar view (e.g. NumberTextBox, CurrencyTextBox), select all the text on it, enter the DOM Node.

The following node does not seem to work:

<input type="text" id="widget" dojoType="dijit.form.TextBox" value="a value" />
<script type="text/javascript">
dojo.connect( dijit.byId('widget'), 'onFocus', function() {
    this.textbox.select();
});
</script>
+3
source share
4 answers

If you use Dojo 1.4 or higher, there is already a property for TextBox called selectOnClick- just set this value to true, and it should do what you want.

, , , , , , this, , , , .

+5

, selectOnClick , .

:

dijit.byId("widgetId").attr("onFocus", function() { this.focusNode.select(); });

. focusNode . INPUT. FilteringSelect, .

+4

, .

-, dijit.byId('widget') Dojo widget (dijit), DOM. DOM. dojo.byId(), , DOM.

Secondly, onFocus will not target the DOM event. DOM events should be all lowercase, so in this situation you will use "onfocus".

Try this code:

dojo.connect( dojo.byId('widget'), 'onfocus', function() {
    dojo.byId('widget').select();
});

This should allow him to work correctly. I replaced this.textbox.select () as I do not see a reference to the object that will be referenced by 'this'.

Try here

+3
source

Since Dojo 1.7:

require(["dojo/on", "dojo/dom"], function(on, dom){

    //direct domNode id method
    on( dom.byId('widget'), 'focus', function() {
        dom.byId('widget').select();
    });

    //via programmatic widget reference
    on( myWidgetReference.focusNode, 'focus', function() {
        myWidgetReference.focusNode.select();
    });

});

Note. Note GreenWebDev is still standing (re: availabilityNode).

0
source

Source: https://habr.com/ru/post/1793748/


All Articles