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

Items/options rendering customization #13

Closed
martinmaillard opened this issue May 26, 2014 · 14 comments
Closed

Items/options rendering customization #13

martinmaillard opened this issue May 26, 2014 · 14 comments

Comments

@martinmaillard
Copy link

It would be great if we could pass a template name (or view class) to ember-selectize instead of optionValuePath and optionLabelPath to customize the way items/options are rendered.

Selectize's render option offers a powerful way to customize display. I guess it is the easiest way to go but it would probably require rendering a view into a string. I don't know if ember allows that.

@miguelcobain
Copy link
Owner

I agree with you, however let me state two things here:

  • optionValuePath and optionLabelPath are desirable as well. The main purpose of this project is to be a drop-in replacement of Ember.Select. Ember takes this approach.
  • Nevertheless, adding support for additional features from Selectize is also desirable (like the item creation which we already support)

That being said, I'm afraid what you're proposing won't be easy. In another project called ember-leaflet, we're trying to use Ember Views for Leaflet popups (you can imagine the advantages). See issue here: gabesmed/ember-leaflet#30.
However, we still haven't found any good way to do that. I believe the problem is very similar.

I'll leave this open to collect people's ideas, and of course, PR are welcome. I'll keep an eye on the issue.

@martinmaillard
Copy link
Author

I agree. I didn't mean that you should remove optionValuePath and optionLabelPath.

@knownasilya
Copy link
Contributor

This should be very possible if not using handlebars.runtime.. maybe using Ember.Handlebars.compile.

@miguelcobain
Copy link
Owner

Would that allow us to have template bindings to a context as well?
Anyway, the possibility of having Views would certainly be more flexible (we could have custom logic encapsulated). But for this simple case, a template name would be great!

Suggestions and PR's are very welcome! Thanks.

@miguelcobain
Copy link
Owner

@knownasilya, as stated in the referenced issue, this is not something easy to accomplish. Not until selectize accepts DOM elements from the render functions.

@miguelcobain
Copy link
Owner

Support for templates and views landed in master.

Now you can use any of the properties
'optionTemplate','itemTemplate','optionCreateTemplate','optgroupHeaderTemplate','optgroupTemplate' 'optionView','itemView','optionCreateView','optgroupHeaderView' and 'optgroupView'.

View takes precedence over template, so if you do strange things like setting optionView and optionTemplate, the latter will be ignored.

Keep in mind that this currently does not work in Ember 1.8.0. See this issue for more info: emberjs/ember.js#5534

@martinmaillard
Copy link
Author

Great ! Thanks :)

@domchristie
Copy link

Does this work in Ember 1.9+?

I’m currently getting an exception when specifying optionTemplate:

TypeError: undefined is not a function
    at exports.default.Ember.default.Component.extend._getStringFromView (http://localhost:4200/assets/vendor.js:93723:12)
    at exports.default.Ember.default.Component.extend._templateToString (http://localhost:4200/assets/vendor.js:93707:19)
    at exports.default.Ember.default.Component.extend.renderOptions.Ember.default.computed.functionNames.forEach.renderFunctions.(anonymous function) (http://localhost:4200/assets/vendor.js:93271:29)
    at $.extend.render (http://localhost:4200/assets/vendor.js:69491:46)
    at $.extend.refreshOptions (http://localhost:4200/assets/vendor.js:68497:24)
    at exports.default.Ember.default.Component.extend.contentArrayDidChange (http://localhost:4200/assets/vendor.js:93589:24)
    at applyStr (http://localhost:4200/assets/vendor.js:29193:29)
    at sendEvent (http://localhost:4200/assets/vendor.js:23343:13)
    at __exports__.default.Mixin.create.arrayContentDidChange (http://localhost:4200/assets/vendor.js:40162:9)
    at EmberObject.extend.arrangedContentArrayDidChange (http://localhost:4200/assets/vendor.js:43974:14)

Ember v1.10.0, Ember-CLI v0.2.0

@miguelcobain
Copy link
Owner

Ember dropped an important API that made this work.
We'll need to find another way to make this work. Meanwhile you can use optionFunction to return an HTML string.

@domchristie
Copy link

OK. Thanks for the update.

@cottrellio
Copy link

Any update on this?

@miguelcobain
Copy link
Owner

I remind you that this repository is not maintained anymore, in favor of the ember-cli addon version (as stated in the README).

1 similar comment
@miguelcobain
Copy link
Owner

I remind you that this repository is not maintained anymore, in favor of the ember-cli addon version (as stated in the README).

@Ramblurr
Copy link

People are getting here from the link in the ember-cli version's readme, maybe that link should be updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants