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

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

Closed
cristijora opened this issue Mar 19, 2017 · 3 comments
Closed

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

cristijora opened this issue Mar 19, 2017 · 3 comments

Comments

@cristijora
Copy link
Collaborator

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?

@lionel-bijaoui
Copy link
Member

Can you do a PR ? And maybe take a look at the test to update them ? Thank you very much !

@cristijora
Copy link
Collaborator Author

Yes, will do a PR later on today.

@lionel-bijaoui
Copy link
Member

Thanks a lot !

cristijora pushed a commit to cristijora/vue-form-generator that referenced this issue Mar 20, 2017
icebob added a commit that referenced this issue Mar 20, 2017
#159 Vue-multiselect doesn't work properly with objects
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