Yapapaya / jquery-cloneya

A jquery plugin to clone DOM elements
MIT License
76 stars 28 forks source link

Possible to start with id=1? #8

Closed jenseo closed 9 years ago

jenseo commented 9 years ago

Hi!

I'm having a scenario where the original element have id's like id="text1" id="container1" and so on. These are crucial for my functions to work, they can't start with no digit at the end. Is it possible, when the cloning is made, to start with this value (text1) and make the clone become text2 for example?

// Jens.

actual-saurabh commented 9 years ago

Yes, you should set the serializeID to false(https://github.com/yapapaya/jquery-cloneya/blob/master/jquery-cloneya.js#L56), so that the default redoIDs function is not run (https://github.com/yapapaya/jquery-cloneya/blob/master/jquery-cloneya.js#L198-L200)

Then on the _clone_beforeappend or _clone_afterappend events, run your own function (https://github.com/yapapaya/jquery-cloneya/blob/master/jquery-cloneya.js#L129-L145)

You could just copy the redoIDs function and modify these lines: https://github.com/yapapaya/jquery-cloneya/blob/master/jquery-cloneya.js#L207-L213

jenseo commented 9 years ago

That's awesome, gonna look into it! Thanks for the quick reply!

jenseo commented 9 years ago

Another question: Can I get the id number of the clone just created? I would like to run a function inside clone_after_append to hide a div with this id number, and hide one with the previous number.

jenseo commented 9 years ago

I might add that I'm now trying to use the default way the plugin is intended.

My function looks like this at the moment, I know it's wrong, but maybe you can point me in the right direction?

$('#formclone').cloneya({
            limit       : 20,
            cloneThis       : '.formPack',
            valueClone      : false,
            dataClone       : false,
            deepClone       : false,
            cloneButton     : '.btnAdd',
            deleteButton    : '.btnDel',
            clonePosition   : 'after',
            serializeID         : true
        }).on('clone_after_append', function(event, toclone, newclone) {
            $(toclone).children(function() {
                $('.tab-container').hide();
                $('.preview').show();
                display_img('bild-upload','for_img');
                display_text('custom-text','for_txt');
                        });
                        $(newclone).children(function() {
                $('.tab-container').show();
                        });
                    });