开发者

How can I clone an input that uses the Masked Input plugin?

I'm using jQuery's Masked Input plugin to help users enter valid input for fields like dates, zip codes, phone numbers, etc. (I'm also using Validate to ensure the form can't be submitted unless things are correct and to offer hints.)

My problem is that I need to be able to clone a row of inputs, which include those using Masked Input. Normally, jQuery's clone(true) will copy any bound events along with the cloned DOM nodes, but for some reason, this doesn't work with Masked Input: clicking in the cloned input causes it to focus on the original one.

I see that the plugin's author has also had this problem, but as far as I know, it hasn't been solved yet.

Does anybody have a workaround? I think I could call unmask() on the new input, then do mask() again to apply the rules from the original, but I don't want to hardcode what those rules are; I want them to be determined from the original input so开发者_JAVA技巧 that I only have to code them in one place.


working with the template plugin jQuery, basic example:

JS:

var 
  id = 0,
  addNewItem = function() {

   var 
       itemNew =  $('#template-item').tmpl({id: id};

   id++;

   $(itemNew).find('.input-a').XPlugin(); // applied any plugin

   $(itemNew).appendTo('#myTable tbody');

  };

for use anywhere. or when an event occurs

addNewItem();

Edit and Update the problem

The problem is the following, this plugin saves the element reference (input) in the variable "var input = $ (this);" (line 85 of "jquery.maskedinput-1.2.2.js"), then uses it to all events and functions. When you want to clone the element, within the plugin, refers to the first element. For this reason this plugin can not be cloned.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜