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

When a null value is needed, it is not included in the options #150

Open
jdhines opened this issue Jun 17, 2016 · 1 comment
Open

When a null value is needed, it is not included in the options #150

jdhines opened this issue Jun 17, 2016 · 1 comment

Comments

@jdhines
Copy link

jdhines commented Jun 17, 2016

I have an array the I use for content, and need to use the value for sorting another part of the display. This array is:

  myOptions: [
    {value: null, label: 'All'},
    {value: true, label: 'Yes'},
    {value: false, label: 'No'}
  ],

And my template has the component declared like so:

{{ember-selectize
    content=myOptions
     selection=selectedOption
     optionValuePath="content.value"
     optionLabelPath="content.label"
}}

But when changing the value of the select in the UI, the controller property selectedOption doesn't change.

Here's some code for a failing test:

var exampleObjectContentWithValueAndNull = function() {
  //have to be in order since mapBy(value) apparently does alphabetically
  return Ember.A([
    Ember.Object.create({
      value: false,
      label: 'false'
    }), Ember.Object.create({
      value: null,
      label: 'null'
    }), Ember.Object.create({
      value: true,
      label: 'true'
    })
  ]);
};

test('optionValuePath passes selectize the desired value', function(assert) {
  var component = this.subject();
  Ember.run(function() {
    component.set('content', exampleObjectContentWithValueAndNull());
    component.set('optionValuePath', 'value');
  });
  this.render();
  assert.deepEqual(exampleObjectContentWithValueAndNull().mapBy('value'), asArray(component._selectize.options, 'value'));
});
@jdhines
Copy link
Author

jdhines commented Jun 17, 2016

Mostly seems to be an issue when the object behind content either has a null value (which might be appropriate, or if the field hasn't been set by the user yet, so that the property behind value is null. In these cases, trying to transition away from the route gives the error Cannot read property 'attr' of null.

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