How to display multiple selections in Editor Selectize from data source?

How to display multiple selections in Editor Selectize from data source?

mrsearing-allmrsearing-all Posts: 9Questions: 3Answers: 0
edited November 2023 in Free community support

I am using Editor with Selectize, which loads the options as expected and I can successfully select multiple options and save to the database. However, when I go to edit that record, specifically the field 'Brands' below, the Selecitze Editor field is blank. If it is just one, then it successfully shows that option as selected.

I've tried creating a custom GetFormatter and the ready-to-use Format methods for the field.

With the custom GetFormatter, I receive the error 'Unable to cast value to be String'

.Field(new Field("Brands")
    .GetFormatter((val, data) => val == null ? Format.NullEmpty() : Format.Explode(","))

Using the ready-to-use Format methods does not seem to alter the data and there is no error, however Selectize does not recognize multiple selections and does not display if there is more than one option selected.

.Field(new Field("Brands")

What is returned with no Formatters or ready-to-use methods:

Brands: "152" //will displayed as selected, but not "152,232"; shows as empty. Can be null
Comments: null
ContactID: 1498
Email: ""
FirstName: "Test"
LastName: "Contact"
Notify: false
Title: "Test Title"
Updated: "2023-11-29T18:13:51.703"

Unfortunately I cannot link to the page but can provide any clarification.

I have read this discussion so I know it needs to be an array but cannot get the format in the server-side code to do so.

This question has an accepted answers - jump to answer


  • mrsearing-allmrsearing-all Posts: 9Questions: 3Answers: 0

    It looks like I may need to use Field.GetValue to set a delegate, but I am not quite sure how to use this. I have searched the forums and other sites for any examples, but have not found a decent example of how it used.

  • mrsearing-allmrsearing-all Posts: 9Questions: 3Answers: 0

    For anyone looking for the same solution, this is how I solved it:

    .Field(new Field("Brands")
                    .GetFormatter((val, data) => val.GetType().ToString() == "System.DBNull" ? null : ((string[])val.ToString().Split(",")))

    And change the property in my class from string to string[]

    For it to save properly, use

    editor.on('preSubmit', function (e, data, action) {
        if (editor.field('Brands').val() !== null && action !== 'remove') {
            let notFormatted = editor.field('Brands').val();
            let keys = Object.keys(;
            let rowID = keys[0];
  [rowID]['Brands'] = notFormatted.toString();
  • colincolin Posts: 15,094Questions: 1Answers: 2,581
    Answer ✓

    Nice, thanks for posting the solution!


Sign In or Register to comment.