A
A
Alexander Wolf2015-12-10 17:02:41
JavaScript
Alexander Wolf, 2015-12-10 17:02:41

How to update textbox value in meteor (as you type)?

Good evening. I have a collection Item. It contains the document { name: 'Abc' }. There is a template:

<template name='a'><div contenteditable>{{name}}</div></template>

Template.a.helpers({
  name() {
    return Items.findOne(...).name;
  }
});

Template.a.events({
  'input div': function(e, tmpl) {
  var item = $(e.currentTarget);
    clearTimeout(item.data('timeout'));

    var id = setTimeout(() => {
      var text = item.text();
      Items.update(this._id, { $set: { name: text } });
      item.val(text);
    }, 500);

    item.data('timeout', id);
  }
});

So, when you enter text, the caret near the field flies to the beginning of the text. This is understandable. The question is how to overcome this behavior? Only by removing reactivity from name?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Wolf, 2016-06-27
@mannaro

This is a Blaze bug. I don't know how things are now. Perhaps they have already decided.
Then I overcame it like this: removed contenteditable :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question