Add value to ComboBox upon creating obj

Enonic version: 6.5.2
OS: Ubuntu

Is it possible to add a value to a ComboBox when creating an object ? Does enonic allows to do that?

Thx in advance!

Example.:

<input name="status" type="ComboBox">
            <label>Status</label>
            <occurrences minimum="0" maximum="1"/>
            <config>
                <option value="someValue">someValue</option>
                <option value="someValue2">someValue2</option>
            </config>
</input>


var projectObj = {
                        parentPath: '/somePath',
                        displayName: title,
                        draft: true,
                        contentType: 'com.x:y',
                        data: {
                            id: projectId,
                            startDate: projectStartDate,
                            endDate: projectFinishDate,
                            status: status,
                            lastModified: lastModified,
                            body: body
                        },
                        x: {},
                        page: {},
                        attachments: {}
 };
  var createProjectResult = contentLib.create(projectObj);

var publishProjectResult = publishProject(createProjectResult._id);

The ComboBoxes only allows you to select between predefined values. Perhaps you should try the Tag input type? It lets you add existing items (via search) and create new ones.

If full dynamic content in ComboBox is needed you have to create a contenttype for the data and use a contentselector.

You should be able to create a content with any value for a ComboBox using contentLib.create(). But it won’t show up in the Content Studio if you use it to edit the content later. For a ComboBox option to appear in the Content Studio, it must exist in the XML schema. Like @bwe said, the tag input will let you add new values.

Are you looking for some kind of conditional dropdown? I did not understand your example?

tsi

I would like to add another option to the input “status” in the example above when creating a content of that type.

Why can’t that be statically declared? If you need a value every time you create something?

I understand your point, it would be a lot easier if we could fix these values. However, this “status: status,” attribute is coming from a XML import file and the values will vary.

This is part of the requirement, having two default values (“someValue”, “someValue2”) and then add another value to it, which will come from the XML import file .

I will study a way around it.

Hmmm, we are working on a new input type where you may implement a controller that feeds the content. Maybe this will solve your requirement?

1 Like

yes, that might solve. :+1:

I will give it a try, I left all options in the ComboBox for now.