-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
x-editables with select2 #431
Comments
hi @phorisc |
I need this function aswell |
Same or similar problem here. After saving new value with select2, editable text node sets to 'Empty'. Success function returns correct value and server-side is also updated, but text node switch to 'Empty' every time.
First console log call returns text value of previous select and second returns Empty. |
I solved my problem with 'display' function. Hope it helps someone.
Now text node updates after saving value with select2. Second version, with support to multiple values:
|
Hi...I cant get it to work. I'm using xeditable for yii...has someone an example? |
@Ninodevo check here: http://x-editable.demopage.ru/ |
doesn't work for me as well. Once I get any option selected and by clicking the save button I get 'Empty' text again. |
on the example page http://vitalets.github.io/x-editable/demo-bs3.html the selected value is being sent to server but what about the case when I don't do that and just display the selected? |
+1 on this. How could we achieve dynamic select2 data with the possibility of adding new items in X-Editable? |
Hi, I think the reason is the code in this section in the value2html: function(value, element) {
var text = '', data,
that = this;
if(this.options.select2.tags) { //in tags mode just assign value
data = value;
//data = $.fn.editableutils.itemsByValue(value, this.options.select2.tags, this.idFunc);
} else if(this.sourceData) {
data = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
} else {
//can not get list of possible values
//(e.g. autotext for select2 with ajax source)
}
//data may be array (when multiple values allowed)
if($.isArray(data)) {
//collect selected data and show with separator
text = [];
$.each(data, function(k, v){
text.push(v && typeof v === 'object' ? that.formatSelection(v) : v);
});
} else if(data) {
text = that.formatSelection(data);
}
text = $.isArray(text) ? text.join(this.options.viewseparator) : text;
//$(element).text(text);
Constructor.superclass.value2html.call(this, text, element); Basically, if the select2 is not in 'tags' mode, you have to provide a if(!options.select2.tags && options.source) {
var source = options.source;
//if source is function, call it (once!)
if ($.isFunction(options.source)) {
source = options.source.call(options.scope);
}
if (typeof source === 'string') {
options.select2.ajax = options.select2.ajax || {};
//some default ajax params
if(!options.select2.ajax.data) {
options.select2.ajax.data = function(term) {return { query:term };};
}
if(!options.select2.ajax.results) {
options.select2.ajax.results = function(data) { return {results:data };};
}
options.select2.ajax.url = source;
} else {
//check format and convert x-editable format to select2 format (if needed)
this.sourceData = this.convertSource(source);
options.select2.data = this.sourceData;
}
} What it took me hours to figure out was that my original code was not setting the I think that either the xEditable Hope this helps anyone encountering the same issue as I did, might save you a wasted evening :-) |
Thanks! You saved me the rest of a wasted evening! |
Thanks, but can you provide with a JSFiddle or some |
@rjsmith - any chance at all of providing a fiddle or some code with this working? You'd save my bacon! |
I am using xEditable within a Meteor.js application via this Meteor lightweight wrapper package. Here is one example of a Meteor Blaze template that wraps a select2 xEditable widget. As I described above, the key here is to pass a 'source' attribute to xEditable.
|
Thank you very much for that - except I'm not using meteor, Could you post your final rendered version of your js (if that's possible?) I don't know much about meteor and I'm failing to understand what your JS would look like after template processing. Also - what version of select2 and xeditable are you using? Here is my fully rendered JS - maybe you can see what I can't:
|
I'm using xEditable bootstrap v1.5.1, with select2 v3.5.1 |
Sorry - the problem is that using select2 dropdown, after successful selection the cell displays 'Empty' exactly like the initial post. The server is updated via ajax call successfully however it just doesn't appear so due to it showing 'empty' in the cell after selecting. You have to reload the page (and pull from the server again) in order to get it to show the correct value. I'll see what I can do to add breakpoints in the select2 code, I may revert back to 3.5.1, I am using 4.4 currently. |
I suggest you put breakpoints in the xeditable Select2 value2html function
which determines how to render the selected value .
…On 14 Oct 2017 4:23 p.m., "ihelmer07" ***@***.***> wrote:
Sorry - the problem is that using select2 dropdown, after successful
selection the cell displays 'Empty' exactly like the initial post. The
server is updated via ajax call successfully however it just doesn't appear
so due to it showing 'empty' in the cell after selecting. You have to
reload the page (and pull from the server again) in order to get it to show
the correct value.
I'll see what I can do to add breakpoints in the select2 code, I may
revert back to 3.5.1, I am using 4.4 currently.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#431 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AApa_U8k_LHwWeYRF2B7boHL_B0nkX1oks5ssNHxgaJpZM4BLFUW>
.
|
I figured out that like you - datasource isn't being set during this function call: $.extend(Constructor.prototype, {
render: function() {
this.setClass();
//can not apply select2 here as it calls initSelection
//over input that does not have correct value yet.
//apply select2 only in value2input
//this.$input.select2(this.options.select2);
//when data is loaded via ajax, we need to know when it's done to populate listData
if(this.isRemote) {
//listen to loaded event to populate data
this.$input.on('select2-loaded', $.proxy(function(e) {
// ****** THIS IS NEVER setting this.sourceData for some reason. List still populates however.
this.sourceData = e.items.results;
}, this));
}
//trigger resize of editableform to re-position container in multi-valued mode
if(this.isMultiple) {
this.$input.on('change', function() {
$(this).closest('form').parent().triggerHandler('resize');
});
}
}, Then because value2html: function(value, element) {
var text = '', data,
that = this;
if(this.options.select2.tags) { //in tags mode just assign value
data = value;
//data = $.fn.editableutils.itemsByValue(value, this.options.select2.tags, this.idFunc);
} else if(this.sourceData) {
data = $.fn.editableutils.itemsByValue(value, this.sourceData, this.idFunc);
} else {
//****THIS IS WHERE WE END UP, meaning data never gets set meaning it displays empty.
// If I knew how to translate an ID value to a text we'd be in business here, but I don't
//***********************************************************
//can not get list of possible values
//(e.g. autotext for select2 with ajax source)
}
//data may be array (when multiple values allowed)
if($.isArray(data)) {
//collect selected data and show with separator
text = [];
$.each(data, function(k, v){
text.push(v && typeof v === 'object' ? that.formatSelection(v) : v);
});
} else if(data) {
//**************************
///this goes to the xeditable formatSelection (which you need to specify), however there is no ability to
take the value given and use the Json object to convert it to text.
//************************
text = that.formatSelection(data);
}
text = $.isArray(text) ? text.join(this.options.viewseparator) : text;
//$(element).text(text);
Constructor.superclass.value2html.call(this, text, element);
}, I could force the array into the 'tags' case using I can't seem to find a way to get access to the json objects array within that function. |
Here's what worked for me with select2 (v4.0.13) and x-editable (v1.5.1)
|
I am using select2 with x-editables. Select2 allows me to modify the query field and i can append a new item to select in the drop down if it doesnt currently exist. Though when i select it and hit the check button the x-editable field remains with the "Empty" text that it originally had but in the back end it knows the right value. Is there somthing i need to do to make it so it updates the "Empty" text to the text of what i selected in the select2 drop down?
The text was updated successfully, but these errors were encountered: