graham73may / bolt-ajax-multi-contenttype-select-field Goto Github PK
View Code? Open in Web Editor NEWAn AJAX based multi-contenttype select field for Bolt CMS.
An AJAX based multi-contenttype select field for Bolt CMS.
return '/bolt/ajax-multi-ct-select?page=' + page;
so, if I hav other branding path than bolt?
(function ($) {
'use strict';
$.fn.extend({
customSelect2Sortable : function (options) {
var select = $(this);
$(select).select2(options);
var ul = $(select).next('.select2-container').first('ul.select2-selection__rendered');
ul.sortable({
items : 'li:not(.select2-search)',
tolerance : 'pointer',
stop : function () {
$($(ul).find('.select2-selection__choice').get().reverse()).each(function () {
var id = $(this).data('data').id;
var option = select.find('option[value="' + id + '"]')[0];
$(select).prepend(option);
});
}
});
}
});
function modifySelect2 () {
var $buicSelects = $('.js-ajax-multi-ct-select');
var len = $buicSelects.length;
var options = {};
var i;
var $buicSelect;
var $select;
for (i = 0; i < len; i++) {
$buicSelect = $($buicSelects[i]);
$select = $buicSelect.find('select');
options = $select.data('select2').options.options;
if (options.ajax === undefined || options.ajax === null) {
options = {
language : {
errorLoading : function () {
return 'Searching...'
}
},
placeholder : options.placeholder,
allowClear : options.allowClear || true,
minimumResultsForSearch : options.minimumResultsForSearch,
width : options.width,
ajax : {
select : $select,
url : function (params) {
var page = params.page || 1;
return '/bolt/ajax-multi-ct-select?page=' + page;
},
dataType : 'json',
delay : 500,
type : 'POST',
data : function (params) {
var $container = this.select.closest('.js-ajax-multi-ct-select-container');
return {
q : params.term, // search term
page : params.page || 1,
field : $container.data('field')
};
},
processResults : function (data, params) {
// parse the results into the format expected by Select2
// since we are using custom formatting functions we do not need to
// alter the remote JSON data, except to indicate that infinite
// scrolling can be used
params.page = params.page || 1;
return {
results : data.results,
pagination : {
more : (data.pager.current * data.pager.limit) < data.pager.count
}
};
},
cache : true
}
};
if ($buicSelect.hasClass('js-ajax-multi-ct-select--sortable')) {
$select.select2('destroy');
options.createTag = function (params) {
return undefined;
};
$select.customSelect2Sortable(options);
} else {
$select.select2('destroy');
$select.select2(options);
}
$buicSelect.find('.select2-selection__placeholder').html('(none)');
}
}
}
$('.repeater-add').on('click', function () {
modifySelect2();
});
$(window).on('load', modifySelect2);
}(jQuery));
may be this
var $container = $(this).closest('.js-ajax-multi-ct-select-container');
replace to
var $container = $select.closest('.js-ajax-multi-ct-select-container');
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.