polymer - Determining if an event target is the child of another element -
i'm trying figure out best way determine parent node event target belongs.
you have custom polymer element 2 or more forms in it. each form has submit button:
<form is="iron-form" id="form1" method="post" action="/action1"> <paper-button on-tap="_submithandler">send<paper-button> </form> <form is="iron-form" id="form2" method="post" action="/action2"> <paper-button on-tap="_submithandler">send<paper-button> </form> ... <form is="iron-form" id="formn" method="post" action="/action3"> <paper-button on-tap="_submithandler">send<paper-button> </form>
then in tag have handler:
_submithandler: function(e) { var path = polymer.dom(e).path; var item = null; var form = null; (var = 0; < path.length; i++) { item = path[i]; switch (item) { case this.$.form1: form = this.$.form1; break; case this.$.form2: form = this.$.form2; break; // ... n cases } } if (form != null) { form.submit() } }
there must better way this... right way handle such case?
i'm using polymer 1.0
try this:
_submithandler: function(e) { var form = var form = polymer.dom(e).parentnode; if (form != null) { form.submit() } }
or this:
_submithandler: function(e) { var form = var form = polymer.dom(e.target).parentnode; if (form != null) { form.submit() } }
Comments
Post a Comment