(Dojo) How set focus to same input, by using widgets dijit?

I need set focus to input, by using widgets dijit. I don now how require property focus() in form._FormWidget.

<script type="text/javascript"
src="http://o.aolcdn.com/dojo/1.6/dojo/dojo.xd.js" djConfig="parseOnLoad: true" >
</script>
<script>
dojo.require("dojo.parser");
dojo.require("dijit.form._FormWidget");
dojo.require("dijit.form.Form");    

var ws = new dijit.form._FormWidget();
ws.focus(dijit.byId("company"));
</script>

<input id="company" type="text" name="company" />

This not working! Pls help.

If use document.getElementById('company').focus(); i hav error Uncaught TypeError: Cannot read property 'focus' of null.

Upvotes: 1

Views: 3665

Answers (1)

Ken Franqueiro
Ken Franqueiro

Reputation: 10559

I'm not 100% sure I get what you're asking, but if you're just looking to focus a simple native HTML input, just call focus on it directly, no Dojo or Dijit required.

document.getElementById('company').focus();

Dijit form widgets tend to have their own focus methods which will do the same thing for their own inputs. You can't call focus on a Dijit widget for the purpose of focusing something other than the widget itself.

Meanwhile, dijit.byId('company') won't return anything on your page since the company input is not a Dijit widget.

Upvotes: 1

Related Questions