Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(document).ready(function()
- {
- var Count = 1;
- $(".entry").children("select").select2({});
- $(".btn-add").click(function () {
- $(".entry")
- .children("select").each(function () {
- $(this)
- // call destroy to revert the changes made by Select2
- .select2("destroy")
- .removeAttr('data-live-search')
- .removeAttr('data-select2-id')
- .removeAttr('aria-hidden')
- .removeAttr('tabindex');
- });
- });
- $(document).on('click', '.btn-add', function(e)
- {
- e.preventDefault();
- var controlForm = $('.controls fieldset:first-child'),
- currentEntry = $(this).parents('.entry:first'),
- newEntry = $(currentEntry.clone()).appendTo(controlForm);
- newEntry.find('input').val('');
- controlForm.find('.entry:not(:last) .btn-add')
- .removeClass('btn-add').addClass('btn-remove')
- .html('<div id="rectangle"></div>');
- $(".entry").children("select").each(function () {
- $(this).select2({});
- });
- }).on('click', '.btn-remove', function(e)
- {
- $(this).parents('.entry:first').remove();
- e.preventDefault();
- $(".entry").children("select").each(function () {
- $(this).select2({});
- });
- return false;
- });
- });
Add Comment
Please, Sign In to add comment