Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attribute to options #1492

Open
marcoheine opened this issue Dec 15, 2023 · 2 comments
Open

Add attribute to options #1492

marcoheine opened this issue Dec 15, 2023 · 2 comments

Comments

@marcoheine
Copy link

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
Copy link
Collaborator

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants