Hello,
I’m trying to get a x-editable / select2 component with reactive options following this example: http://stackoverflow.com/a/36323435. Use case is to show a select field for adding users to a team. The select options consist of suggested users, who are not already team mates. Every time a new user is added to the team, suggested users are recalculated and delivered to current data context by parent template helper.
This is my onRendered function:
Template.addMember.onRendered(function() {
var tmplInst = this;
this.autorun(function() {
data = Blaze.getData();
tmplInst.$('.add-member').editable("destroy").editable({
type: 'select2',
title: "add member",
placeholder: "Choose a member",
emptytext: "Add a member",
validate: function(value) {
if($.trim(value) == '') {
return "Please choose a member!";
}
},
source: function() {
return data.suggestedUsers;
},
success: function(response, newValue) {
var draftId = $(this).data("pk");
ProjectDrafts.update(draftId, {$push: { team: {userId: newValue} } });
$(this).editable("value", null);
},
});
});
});
Sometimes it works all as expected, but sometimes (only when whole page is reloaded) the editable is not shown up at all and I get this error in Chrome console:
TypeError: Cannot read property 'data' of undefined
at Constructor.destroy (bootstrap-editable.js:3893)
at Editable.destroy (bootstrap-editable.js:1939)
at HTMLAnchorElement.<anonymous> (bootstrap-editable.js:2143)
at Function.each (jquery.js:384)
at jQuery.fn.init.each (jquery.js:136)
at jQuery.fn.init.$.fn.editable (bootstrap-editable.js:2125)
at Blaze.View.<anonymous> (new_project.js:190)
at view.js:199
at Function.Template._withTemplateInstanceFunc (template.js:465)
at view.js:197
Any suggestions? Thanks in advance!