Mottie / Keyboard

Virtual Keyboard using jQuery ~
http://mottie.github.io/Keyboard/
Other
1.78k stars 723 forks source link

It doesn't work on dynamically created rows #521

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hey there, so I can't seem to submit or type inside the rows that are dynamically created.

https://jsfiddle.net/Lsact1tv/

I've already searched and found other topics about that, but they didn't help me. Any suggestions? Thank you! :)

Mottie commented 7 years ago

Hi @exyoris!

Currently, the keyboard needs to be bound to an element directly, no delegated binding, as more than one keyboard is permitted to be open at a time and each may have a different layout.

I ended up modifying a few things in the demo to get things working - updated demo

$(function() {

  var settings = {
    usePreview: false,
    position: {
      of: '#keyboard-wrapper',
      my: 'center top',
      at2: 'center bottom',
      offset: '0 20'
    }
  };

  $('.keyboard').keyboard(settings);

  var id = 0;
  jQuery("#addrow").click(function() {
    id++;
    var row = jQuery('.samplerow tr').clone();
    row.find("input:text").val("");
    row.attr('id', id);
    row.appendTo('#dynamicTable1');
    row.find('.keyboard').keyboard(settings);
    return false;
  });

  $('.remove').on("click", function() {
    $(this).parents("tr").remove();
  });
});
ghost commented 7 years ago

Thank you, Mottie! This did the trick. :)

Mottie commented 7 years ago

I'm guessing this issue has been resolved, so I'm going to close it. If you continue to have problems, please feel free to continue the discussion in this thread.