Skip to content

Selectize does not work for addOption() with option value=null #1648

@FritzHerbers

Description

@FritzHerbers

I did:

  • Search for if my issue has already been submitted
  • Make sure I'm reporting something precise that needs to be fixed
  • Give my issue a descriptive and concise title
  • Create a minimal working example on JsFiddle or Codepen
    (or gave a link to a demo on the Selectize docs)
  • Indicate precise steps to reproduce in numbers and the result,
    like below

[replace me with a short description of issue]

Steps to reproduce:

Expected result:
Having the possibility to add an option with value=null to be added with addOption()

Actual result:
selectize does not allow to add an option with value=null with addOption().

When using selectize in html mode value=null seems to work: https://jsfiddle.net/v79613p4/

I am using Angular with ng-selectize, which uses selectize.
I could identify the problem in addOption():

registerOption: function(data) {
	var key = hash_key(data[this.settings.valueField]);
	if (typeof key === 'undefined' || key === null || this.options.hasOwnProperty(key)) return false;
	data.$order = data.$order || ++this.order;
	this.options[key] = data;
	return key;
},

When typeof key === 'undefined' || key === null || is removed the option can be added and is visible, but now the option can not really be selected, the select dropdown box stays open. The box closes only when a 'valid' option is choosen.

I do not have experience of setting up a selectize/javascript project. I have been searching for jsfiddle/codepen examples to kickstart and narrow down the issue, haven't found any. It would be nice when the project could create some for the demos, which then can be used as a starting point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-thoughtpending reviewThis issue was closed as stale; since then additional review has been requested.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions