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

Problems with defaultOption as a function, returning false #303

Open
nim-ohtar opened this issue Mar 8, 2016 · 0 comments
Open

Problems with defaultOption as a function, returning false #303

nim-ohtar opened this issue Mar 8, 2016 · 0 comments

Comments

@nim-ohtar
Copy link

Hello there,

I am having some troule with slectOptions, more precisely with defaultOption.
I am having the following scenario, there is a select which should have defaultOption in some cases and in others not. I am using the defaultOption property as a function to determine the correct default value.
Here is an example:

defaultOption: function(){
                    var selectedValue = this.model.get("value");

                    if (!selectedValue){
                        return {
                            label: "Veuillez sélectionner une valeur",
                            value: ""
                        };
                    } else {
                        return false;
                    }
                }

Problem is default option is still added, as if

defaultOption: { label: "", value: "" }

is applied. I could not find appropriate workaround for this, so I checked the code.
The code in question is the following:

 if (selectConfig.defaultOption) {
    var option = _.isFunction(selectConfig.defaultOption) ?
      selectConfig.defaultOption.call(this, $el, options) :
      selectConfig.defaultOption;
     addSelectOptions(["__default__"], $el, option);
  }

My suggestion is this change:

  if (selectConfig.defaultOption) {
    var option = _.isFunction(selectConfig.defaultOption) ?
      selectConfig.defaultOption.call(this, $el, options) :
      selectConfig.defaultOption;
      //changed code
      if (option) {
          addSelectOptions(["__default__"], $el, option);
      }
  }

If you guys, can help me out with an appropriate workaround or feedback for the proposed change I would appreciate it.
Thanks

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

1 participant