1

I do not know why after adding new input, Masked Input Plugin does not work on it(new input)?

Example: http://jsfiddle.net/yx5wa/1/

$('a.add_input').live('click', function (event) {
    event.preventDefault();
    var newDiv = $($(this).closest('.adding').get(0)).clone(true);
    $(this).closest('.adding').find('.add_input').remove()
    newDiv.find('.adda').not(':has(.remove_input)').append('<div class="mediumCell"><a href="" class="remove_input">remove</a></div>')
    newDiv.hide().fadeIn('slow')
    $('.adding:last').after(newDiv);
    $('.adding' + ':last input:checkbox').prop('name', 'checkbox_units[' + size_un + '][]');
    console.log($('.adding:last input:checkbox').prop('name'));
});

1 Answer 1

1

It looks like there were two issues:

  1. The plug-in needs to be applied again to the new input within your click event:

    newDiv.find('input').mask("9999/99/99");
    
  2. The clone function needs to be called with withDataAndEvents set to false:

    var newDiv = $($(this).closest('.adding').get(0)).clone(false);
    

It seems like you were trying to clone the input and then use .clone(true) to bring the mask functionality along for the ride (right?). Unfortunately, it looks like this won't work. You can see in this fiddle, when I try and clone the input, it looks like references to the original input are still stuck in there, creating some strange behavior.

Sign up to request clarification or add additional context in comments.

2 Comments

how can type date of right to left in input rtl(start typed of day and end typed year),(the first typed is the day, the second typed is the month, the third typed is the year => third typed-year/second typed-month/first typed-day) and format it is like: 2011/09/05
@Jennifer Anthony That's a complex enough question that you should probably open it up as a separate question (that way you can get the best implementation of it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.