Sunday, July 26, 2009

[jQuery] jQuery plugin - not having to call multiple times

I'm working on a plugin that basically creates form elements, it's
called like this:

$('#form').formBuilder({
type: 'select',
id: 'selectBox',
cssClass: 'form-item',
name: 'select',
});


This would then append a select box within the form. If I want to add
more inputs, I have to repeat this code.

I was wondering if there is a way that I could call it like this:

$('#form').formBuilder({
type: 'select',
id: 'selectBox',
cssClass: 'form-item',
name: 'select',
},{
type: 'select',
id: 'selectBox2',
cssClass: 'form-item',
name: 'select',
});

So that I don't have to repeat $('#form').formBuilder for every item,
as it's redundant.

Any help would be great! Thank you.

No comments: