GithubHelp home page GithubHelp logo

graham73may / bolt-ajax-multi-contenttype-select-field Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 3.0 18 KB

An AJAX based multi-contenttype select field for Bolt CMS.

PHP 60.72% HTML 18.30% JavaScript 20.98%
bolt-cms

bolt-ajax-multi-contenttype-select-field's People

Contributors

fathimasmat avatar graham73may avatar jarjak avatar mrenigma avatar

Stargazers

 avatar

Watchers

 avatar  avatar

bolt-ajax-multi-contenttype-select-field's Issues

other branding path

return '/bolt/ajax-multi-ct-select?page=' + page;

so, if I hav other branding path than bolt?

Apply JS Fix from [private] project

(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));

empty ajax response

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');

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.