Yapapaya / jquery-cloneya

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

reset option #13

Closed gchokeen closed 8 years ago

gchokeen commented 9 years ago

Cloneya needs a reset option, when I come across form reset(without page reload), plugin keeps all the cloned form fields. It has to be reset. so it will be great if we add a rest option.

razuro commented 9 years ago

Yup. I second that.

actual-saurabh commented 9 years ago

The simplest way to do that is to deep clone the cloneya element and keep it in memory. To reset, we just replace whatever we have with what's stored in memory:

$stored_elem = $element.clone({
    withDataAndEvents: true,
    deepWithDataAndEvents: true
});

$element.cloneya();

$reset_button.on('click', function(e){
    e.preventDefault();
    $element.replaceWith($stored_elem);
});

There are many bloated, super feature rich, css and graphic rich, user centric cloning plugins out there. Cloneya is not that. Anything that is not essential or doesn't directly influence the process of cloning need not be included.

TLDR, this can stay outside cloneya. Those who need a reset can simply use the code above.

In fact, looking at the kind of requests we get, it'll be great to compile these examples and concepts (especially index manipulation) into tutorials or wiki or both.

However, there might be arguments to the contrary. What do you say?

gchokeen commented 9 years ago

Solution is simply great! I agreed many rich plugin doing that sometime even small one's. Because I see reset is become basic feature when it comes to single page applications. I see even developers don't want to do much code outside (Lazy!). Anyhow, Let's say based on number request on same feature we think of adding it later!

It's really good point about expanding wiki or tutorial, it will be useful!

actual-saurabh commented 9 years ago

Cool, let's add this in 1.0.

actual-saurabh commented 9 years ago

Now I have doubts again.

Storing the whole form in memory is not a very nice thing to do. So, we may have to append it to a hidden div and then retreive from there. Is there a performance diference between the two?

Regardless of the above, I think I'll keep this out of cloneya and create a separate plugin that the user may or may not want to include.