Add "options" to custom field type

Hi,

I’m creating a custom field type by following this guide. Now, I want to add some customization to the field by providing similar “options” as the TextOption field, where you can add your own options to the dropdown with a label and a value.

How do I do this for my custom field? The IEditFieldTypeConverter class contains a function, “CreateOptionsModel”, which I guess has something to do with it, but there’s no documentation what to do with this function or if its the right one.

Any pointer would be of help! :slight_smile:

Litium version: 7.6.1

Progress…

I found some ancient examples where new TextOption(); was returned in the CreateOptionsModel() which partially works. The “options” collapsible is now visible in the backoffice when configuring the field. However, it looks like I have to rebuild the whole “TextOption” options view?

When inspecting the html code of normal TextOption field when configuring it, I can see that a directive is used, field-editor-text-option-setting, but there’s no documentation for this as well.

I created a plain angular component and included it in the “declarations” array in the extensions.ts file, and then set the name of SettingsComponentName to Accelerator#TestSettings which showed the settings component. But, I’d rather not rebuild the TextOption settings view, if possible.

I think you could re-use the standard settings component, try using FieldEditorTextOptionSetting as your SettingsComponentName.

Worked great.

Another question, is it possible to translate website strings in the component? I can’t find any documentation for this as well.

Yes, keys and translations can be added to the resource files in the Accelerator to use translated strings in your field component. You can see in the FilterField from the Accelerator:

    <div title>
        {{ 'dialog.sortDialog.fields.title' | translate }}
    </div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.