1

i am adding polymer elements. i want to remove the element(self) on click on its(own) image. as per encapsulation i will have to make the parent delete the child. but this requires requires generating polymer elements for the parent too( am i right here??). children.add not defined for polymer elements.how do i do this, i plan to do some checks before adding the polymer element to the form .

Already read: How to remove a child component with a delete button in the child itself

How do I fire a custom event from Polymer Dart?

How do you dispatch and listen for custom events in Polymer?

what do i pass through dispatch event??

init-item.html

<polymer-element name="init-item" >
  <template>
    <input type="image" src="button_minus_red.gif" on-click="{{remove}}" width = "15" height ="15">
    {{Name}}<br> 
  </template>
  <script type="application/dart" src="init-item.dart"></script>
</polymer-element>

init-item.dart

@HtmlImport('init-item.html')
import 'dart:html';
import 'dart:async';
import 'package:polymer/polymer.dart';
@CustomTag('init-item')
class PItem extends PolymerElement{
  @observable String Name='hello';
  void remove(){
    Name='';

  }

so presently on clicking the image the name attribute gets reset. but this happens only on a subsequent click event generated from main.dart. This is due to data binding. how do i initiate two way data binding.??

main.html (polymer tags not added inspite of suggestion. couldnt figure it out)

...
<form  id="youritems">
</form>
...

Polymer items added to above tag.

main.dart

...
main() async{
.. initPolymer().then((_) {});
}
..
...{..
var input = new InputElement(type:"image");
input.onClick.listen((p){
            p.preventDefault();
            populateYourPlayers(teams[i]);
          });
}
void populateItems(String name){
  Polymer.onReady.then((_) { 
    var pl = new Element.tag('player-item');
    pl.playerName = name;
    yourPlayer.children.add(pl);
    });
}
..
Community
  • 1
  • 1
Hemant
  • 69
  • 2
  • 10

1 Answers1

1

If you rename the click handler from remove to for example removeItem then you can just call remove() within the handler and it will work.

<input type="image" src="button_minus_red.gif" on-click="{{removeItem}}" width = "15" height ="15">
void removeItem(){
  Name='';
  remove(); // removes the init-item (self)
}

remove is an existing method on all elements. If you name your own method remove you override the default remove method and the original can't be called anymore (except from within your element with super.remove();)

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • how do i code an event in one polymer to change attributes of another polymer, them not having parent child relation?? – Hemant Apr 12 '15 at 18:52
  • `import 'dart:html' as dom; import 'other_element.dart'; ... (dom.querySelector('* /deep/ other-element') as OtherElement).someField = false;` This searches the whole document for `` even when it is inside the shadow DOM of another element. – Günter Zöchbauer Apr 12 '15 at 18:53
  • aim was to have an event in polymer a to change on attribute in polymer b. (within a.dart: imported b into a. did a query selector for element b. called the function which moded the value. the value changes(print)). but not updated on ui . modded variable is observable. – Hemant Apr 12 '15 at 19:27
  • Sorry, I have no idea what you want to know. Please create a new question with some code that shows what you try to accomplish. – Günter Zöchbauer Apr 12 '15 at 19:29
  • http://stackoverflow.com/questions/29593782/event-in-one-polymer-to-change-attributes-of-another-polymer-them-not-having-pa – Hemant Apr 12 '15 at 19:40