Hi,
I had the same problem : how to use many instances of a plugin on only one form ?
The usual way fail because in fact, the instance is not an instance of the plugin : it is an instance of jQuery.
So, if more than one element is defined to be managed by a plugin, each definition overide the previous parameters.
It was necessary to have a lok on the problem from another side.
A plugin is usualy made to react on an specific event for a specific element. I.E. onclick on a button, or when the mouse is over the element.
In my case, i had to use an autocomplete plugin for a city field, but my form has 5 tabs and in total 4 fields for the cities for 4 different parts of the informations to be collected.
For each fields, parameters are specifics.
By the way, I've realised i don't need to have the plugin active everytime : just on the appropriate event on the field is enought.
So i had an idea : an event manager for each element. When the event appends, so i define the plugin action.
Some code will be more efficient to explain : imagine you have 3 div blocs and your plugin must change the colours, but with specifics colours depending witch div is affected.
$(document).ready(function(){
// Wich elements are affected by the plugin
var ids = ['myDiv1','myDiv2','myDiv3'];
// foe each one :
for (v in ids)
{
//define from an event :
$('#'+ ids[v]).focus(function()
{
// depending wich id is active :
var aParams, idDiv = $(this).attr('id');
// Choosing the right params
switch(idDiv)
{
case 'myDiv1':
aParams = {'color': '#660000', 'background-color': '#0000ff'};
break;
case 'myDiv2':
aParams = {'color': '#006600', 'background-color': '#ff00ff'};
break;
case 'myDiv3':
aParams = {'color': '#000066', 'background-color': '#ff0000'};
break;
default:
aParams = {'color': '#000000', 'background-color': '#ffffff'};
};
// Defining the plungin on the right element with the right params
$(this).myPlugin(
{
colors: aParams
});
});
}
});
And this works fine :)
Sorry if my english is not perfect i hope you understand well.
Enjoy ;)