How can I prevent default event in a child view in backbone
The parent view is actually a form which submits data to the server.
The child view it is a component which is an extension of the parent view and it has couple of interactions: able to add remove items before submission
the child view`s important markup
<input class="tags search-input" type="text" name="search" evt="keyup=search"
id="search-tags" autocomplete="off" placeholder="Search for tag"/>
this will be populated as ul
and user can select multiple options
In my child view I have the following method which adds items to the form on key enter, but should be prevented to fire the parents view submit action
var ChildView = Parent.View.extend({
render: function() {
/* the view is rendered twice because of parent view so I use this*/
Parent.View.prototype.render.apply(this);
// selector inits as var and other event bindings related to this view
},
search: function(e) {
switch(e.keyCode) {
case 13:
e.preventDefault();
e.stopPropagation();
console.log(e)
//execute model task
break;
default:
//default model task
break;
}
}
})
but this code actually tries to execute parents view submit action. I would like to prevent