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

Fixing bugs for select2 editable #1015

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/editable-form/editable-form.js
Expand Up @@ -159,15 +159,17 @@ Editableform is linked with one of input types, e.g. 'text', 'select' etc.
showForm: function(activate) {
this.$loading.hide();
this.$form.show();
if(activate !== false) {
this.input.activate();
}

/**
Fired when form is shown
@event show
@param {Object} event event object
**/
this.$div.triggerHandler('show');

if(activate !== false) {
this.input.activate();
}
},

error: function(msg) {
Expand Down
29 changes: 11 additions & 18 deletions src/inputs/select2/select2.js
Expand Up @@ -204,22 +204,17 @@ $(function(){
},

value2input: function(value) {
// if value array => join it anyway
if($.isArray(value)) {
value = value.join(this.getSeparator());
// Init select2 if not already initialized
if(!this.$input.data('select2')) {
this.$input.select2(this.options.select2);
}

//for remote source just set value, text is updated by initSelection
if(!this.$input.data('select2')) {
this.$input.val(value);
this.$input.select2(this.options.select2);
} else {
//second argument needed to separate initial change from user's click (for autosubmit)
this.$input.val(value).trigger('change', true);
//second argument needed to separate initial change from user's click (for autosubmit)
this.$input.val(value).trigger('change', true);

//Uncaught Error: cannot call val() if initSelection() is not defined
//this.$input.select2('val', value);
}
//Uncaught Error: cannot call val() if initSelection() is not defined
//this.$input.select2('val', value);

// if defined remote source AND no multiple mode AND no user's initSelection provided -->
// we should somehow get text for provided id.
Expand Down Expand Up @@ -298,10 +293,8 @@ $(function(){
},

destroy: function() {
if(this.$input) {
if(this.$input.data('select2')) {
this.$input.select2('destroy');
}
if(this.$input && this.$input.data('select2')) {
this.$input.select2('destroy');
}
}

Expand All @@ -310,9 +303,9 @@ $(function(){
Constructor.defaults = $.extend({}, $.fn.editabletypes.abstractinput.defaults, {
/**
@property tpl
@default <input type="hidden">
@default <select>
**/
tpl:'<input type="hidden">',
tpl:'<select>',
/**
Configuration of select2. [Full list of options](http://ivaynberg.github.com/select2).

Expand Down