Skip to content

Vue-multiselect doesn't work properly with objects #159

Closed
@cristijora

Description

@cristijora

Version: vue-form-generator 2.0.0-beta.15

Scenario:
Copy pasted the example from https://icebob.gitbooks.io/vueformgenerator/content/fields/vuemultiselect.html (simple object select)

Result:
In the select list option I get the whole objects including their fields
multiselectissue

Expected:
In the select list options I have only text values according to the label prop I have set.
In this case, only name should be shown (Vue.js, Rails, Sinatra) just the same as in the official vue multi select docs. http://monterail.github.io/vue-multiselect/#sub-single-select-object

Cause:
It seems that customLabel function from the fieldMultiSelect has some wrong logic in it:

customLabel(){
        if (typeof this.schema.selectOptions !== "undefined" && typeof this.schema.selectOptions.customLabel !== "undefined" && this.schema.selectOptions.customLabel === "function") {
          return this.schema.selectOptions.customLabel;
        } else {
          return function(currentLabel){return currentLabel;};
        }
      }

This bit return function(currentLabel){return currentLabel;}; returns the whole object instead of returning the necessary label only. Also a specified customLabel function doesn't work because of this check this.schema.selectOptions.customLabel === "function" which has a missing typeof before it.
Here is an alternative:

customLabel(){
        if (typeof this.schema.selectOptions !== "undefined" && typeof this.schema.selectOptions.customLabel !== "undefined" && typeof this.schema.selectOptions.customLabel === "function") {
          return this.schema.selectOptions.customLabel;
        } else {
          return undefined;
        }
      }

Since the vue-multiselect library has it's own way of handling default values why not pass an undefined to it when there is no customLabel provided by the user and let the library handle it's stuff?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions