select: add sourceOptions
to modify source request method and params
This commit is contained in:
parent
1329e0ccf9
commit
a55f38ab60
@ -3,6 +3,7 @@ X-editable changelog
|
||||
|
||||
Version 1.5.0 wip
|
||||
----------------------------
|
||||
[enh] select: add `sourceOptions` to modify source request method and params (vitalets)
|
||||
[enh #377] add bool option `escape` to allow html as content (vitalets)
|
||||
[bug #344] fix determing empty for html content (vitalets)
|
||||
[enh] update select2 to 3.4.3 (vitalets)
|
||||
|
@ -117,8 +117,8 @@ List - abstract class for inputs that have source option loaded from js array or
|
||||
}
|
||||
}
|
||||
|
||||
//loading sourceData from server
|
||||
$.ajax({
|
||||
//ajaxOptions for source. Can be overwritten bt options.sourceOptions
|
||||
var ajaxOptions = $.extend({
|
||||
url: source,
|
||||
type: 'get',
|
||||
cache: false,
|
||||
@ -153,7 +153,11 @@ List - abstract class for inputs that have source option loaded from js array or
|
||||
$.each(cache.err_callbacks, function () { this.call(); });
|
||||
}
|
||||
}, this)
|
||||
});
|
||||
}, this.options.sourceOptions);
|
||||
|
||||
//loading sourceData from server
|
||||
$.ajax(ajaxOptions);
|
||||
|
||||
} else { //options as json/array
|
||||
this.sourceData = this.makeArray(source);
|
||||
|
||||
@ -313,7 +317,17 @@ List - abstract class for inputs that have source option loaded from js array or
|
||||
@default true
|
||||
@since 1.2.0
|
||||
**/
|
||||
sourceCache: true
|
||||
sourceCache: true,
|
||||
/**
|
||||
Additional ajax options to be used in $.ajax() when loading list from server.
|
||||
Useful to send extra parameters (`data` key) or change request method (`type` key).
|
||||
|
||||
@property sourceOptions
|
||||
@type object|function
|
||||
@default null
|
||||
@since 1.5.0
|
||||
**/
|
||||
sourceOptions: null
|
||||
});
|
||||
|
||||
$.fn.editabletypes.list = List;
|
||||
|
@ -791,5 +791,37 @@ $(function () {
|
||||
ok(p.find('select').length, 'select exists')
|
||||
equal(p.find('select').val(), 3, 'selected value correct');
|
||||
});
|
||||
|
||||
|
||||
|
||||
asyncTest("sourceOptions", function () {
|
||||
expect(3);
|
||||
var e = $('<a href="#" data-type="select" data-value="2" data-source="sourceOptions">customer</a>').appendTo(fx).editable({
|
||||
sourceOptions: {
|
||||
type: 'post',
|
||||
data: {
|
||||
a: 1
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.mockjax({
|
||||
url: 'sourceOptions',
|
||||
type: 'post',
|
||||
response: function(settings) {
|
||||
equal(settings.data.a, 1, 'params sent!');
|
||||
this.responseText = groups;
|
||||
}
|
||||
});
|
||||
|
||||
e.click();
|
||||
var p = tip(e);
|
||||
|
||||
setTimeout(function() {
|
||||
equal(p.find('select').find('option').length, size, 'options loaded');
|
||||
equal(p.find('select').val(), e.data('editable').value, 'selected value correct') ;
|
||||
|
||||
e.remove();
|
||||
start();
|
||||
}, timeout);
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user