subview focus?

16 views
Skip to first unread message

ladd.james

unread,
Oct 16, 2012, 3:48:51 AM10/16/12
to mari...@googlegroups.com
During my main views constructor I initialize each of my child views in what I think is
the standard Maria way (from Maria checkit example):

constructor: function() {
        maria.ElementView.apply(this, arguments);
        this.appendChild(new checkit.TodosInputView());
        this.appendChild(new checkit.TodosToolbarView());
        this.appendChild(new checkit.TodosListView());
        this.appendChild(new checkit.TodosStatsView());
    },

What I am wondering is how to know when to set focus to a field
in one of my subviews? For instance, in the above I might want to
set focus to the TodosInputView input field when the view is visible.



Peter Michaux

unread,
Oct 16, 2012, 11:07:35 AM10/16/12
to mari...@googlegroups.com
Hi James,
The parent view needs to know which view to focus and when the parent
view is told to focus then it sends the message to the correct child
view to focus.

maria.ElementView.subclass(checkit, 'TodosAppView', {
constructor: function() {
maria.ElementView.apply(this, arguments);
this._inputView = new checkit.TodosInputView();
this.appendChild(this._inputView);
this.appendChild(new checkit.TodosToolbarView());
this.appendChild(new checkit.TodosListView());
this.appendChild(new checkit.TodosStatsView());
},
properties: {
focus: function() {
this._inputView.focus();
},
//...

maria.ElementView.subclass(checkit, 'TodosInputView', {
properties: {
focus: function() {
this.find('.new-todo').focus();
},
//...

Now the bootstrapping code can do

var view = new checkit.TodosAppView(model);
document.body.appendChild(view.build());
view.focus();

Peter
Reply all
Reply to author
Forward
0 new messages