Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

jquery - Select2 4+ Not Tagging with Ajax Call

Code appears right, but I am not getting any triggers on createTag (ie: console.log not getting written / no alert) and I cant even type in year_filter. Initial values are coming from a parent select that populates year_filter but I want the user to be able to add a year if it doesnt current exist:

    $("#year_filter").select2({
        tags: true,
        createTag: function (params) {
            alert('tag created');
            console.log('testing 123 f-me');
            // Don't offset to create a tag if its not 4 digits long and is not numeric
            if ((params.term.length != 4) && (!params.term.match(/d{4}/))) {
                // Return null to disable tag creation
                return null;
            }

            return {
                id: params.term,
                text: params.term,
                newTag:true
            }
        },
        minimumResultsForSearch: Infinity,
        placeholder: "Select A Year",
        ajax: {
            url: "{{route('baadmin.students.get_student_bursary_enrolment_course_module_years')}}",
            type: "post",
            dataType: 'json',
            delay: 250,
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            data: function (params) {
                return {
                    parent_id: $("#student_bursary_enrolment_id").val(),
                    search: params.term // search term
                };
            },
            processResults: function (response) {
                return {
                    results: response
                };
            },
            cache: true
        }
    });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...