kevinchappell / formBuilder

A jQuery plugin for drag and drop form creation
https://formbuilder.online
MIT License
2.63k stars 1.4k forks source link

Add attribute to options #1492

Open marcoheine opened 11 months ago

marcoheine commented 11 months ago

In the options, there are the three attributes "selected", "label" and "value". Is it possible to add custom attributes to the options ("optionTemplate")? I need a custom textarea and a custom checkbox for each option.

Thanks!

lucasnetau commented 10 months ago

Not out of the box. I suggest you make a custom control plugin that will enhance the options with the required additional fields, you will need to handle saving the inputs into the field and loading the formData

lucasnetau commented 8 months ago

Hi @marcoheine,

While cleaning up some documentation I discovered that onAddOption callback allows you to add additional fields to the option list. The feature isn't well documented so I'm writing tests for it now and will add to the documentation.

Take a look at the example on https://formbuilder.online/docs/formBuilder/options/onAddOption/

        onAddOption: (optionTemplate, optionInfo) => {
            console.log('here i am');
            console.error('here i am');
            optionTemplate.label = `Option ${optionInfo.index + 1}`;
            optionTemplate.value = `option-${optionInfo.index + 1}`;
            optionTemplate.customText = `custom-text-${optionInfo.index + 1}`;
            optionTemplate.customBool = false;

            return optionTemplate;
        },

You'll need to work on CSS styling.

image