Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

on-change event not firing properly when binding value

I have this html code:

<textarea id="text-to-convert" on-change="change" value="{{text}}"></textarea>

And this dart code:

import "dart:html";
import 'package:polymer/polymer.dart';

@CustomTag('dictionary-converter')
class DictionaryConverter extends PolymerElement with ObservableMixin {

  @observable String text = "Initial text";

  void change(Event event, var detail, TextAreaElement textElement) {
    print(textElement.value);
    print(text);
  }

}

In this case, the on-change event is only triggered from time to time. (I haven't yet figured out when exactly).

When I remove the value={{text}} binding, the event is properly fired every time the textare is changed.

Am I overlooking something or is this a bug?

like image 909
enyo Avatar asked Oct 03 '13 12:10

enyo


People also ask

Why Onchange event is not working in angular?

Hi, this is because when we use [(ngModel)] where Input and Event binding are as one, every time you change the value of your input, it will also update at the same time but if we were to separate the Input and Event Binding, implementing [ngModel] and (ngModelChange), the angular doesn't know the new value being input ...

What triggers Onchange event?

The onchange event occurs when the value of an element has been changed. For radiobuttons and checkboxes, the onchange event occurs when the checked state has been changed.

Which event triggers when the element has finished changing?

The change event triggers when the element has finished changing.

How do I create a trigger drop change event?

In the click event handler function, we are setting the value of select element to “marks” which is one of the options in the dropdown list and calling triggerChange() method by passing select element as parameter.


1 Answers

With Polymer 0.8+ you can use *yourFieldName**Changed. When the observed property changes, the Changed method will be called. Since String text is two way data bound, changing the value of the textarea will change the value of String text and call the textChanged method. This works with your original code and doesn't need ObservableBox

import "dart:html";
import 'package:polymer/polymer.dart';

@CustomTag('dictionary-converter')
class DictionaryConverter extends PolymerElement with ObservableMixin {

  @observable String text = "Initial text";

  textChanged(oldValue) {
    print("textarea: ${this.shadowRoot.query("textarea").value}");
    print("text: ${text}");
  }
}
like image 157
Nathanial Avatar answered Sep 19 '22 16:09

Nathanial