mdelrosso / sheepit

SheepIt! Form Cloning plugin for Jquery
http://www.mdelrosso.com/sheepit/
MIT License
68 stars 44 forks source link

Moving formFields to options in sheepIt jquery plugin #19

Open christophediprima opened 11 years ago

christophediprima commented 11 years ago

Hi Mariano,

First I would like to thank you for sheepIt. This is a very useful plugin! Then I would like to submit you a proposal to improve the way it can be used.

I tried to implement jQuery select2 in a sheepIt form using the callback function afterAdd.

// Initialize sheepit fieldsets $('.sheepit').sheepIt({ separator:'', afterAdd: function(source, clone) { clone.extendSelect2s(); // extend select2 apply select2 to all clone children } });

Select2 plugin add a additional input with no id, no name and no template attributes but only behaviors that correctly link it to the select2 plugin. However sheepit fails executing if it finds these additional inputs with no templating attributes.

I propose to make formFields selector an option in stead of a simple var in the plugin so we can do this :

// Initialize sheepit fieldsets $('.sheepit').sheepIt({ formFields: "input:not(.select2-input), checkbox, select, textarea", separator:'', afterAdd: function(source, clone) { clone.extendSelect2s(); } });

What do you thing about this?

Cheers, Christophe Di Prima