select2: double initialValue request?

select2: double initialValue request?

BelortaBelorta Posts: 13Questions: 3Answers: 0

Hello,

I have an editor that's displayed on the page using the onPageDisplay function. Some of the fields are select2 objects using ajax as data source.
When the form is shown, I see 2 initialValue requests for each of the select2 fields ("http://localhost:53686/Registraties/getOptions/TYB?initialValue=true&value=%22%22"). Is this to be expected?
(Sorry, but I can't make this accessible online to debug...)

The form is shown as follows:

        editor
            .buttons({
                label: "Save",
                fn: function () { this.submit(); }
            })
            .create(1, true, {
                focus: null
            });

Example of a select2-field definition:

                {
                    "label": "type behandeling",
                    "name": "TYB",
                    "type": "select2",
                    "opts": {
                        placeholder: '...',
                        ajax: {
                            dataType: "json",
                            url: '/Registraties/getOptions/TYB',
                            data: function (params) {
                                return {
                                    productid: ProductID
                                };
                            },
                            processResults: function (data) {
                                return {
                                    results: data
                                };
                            },
                        }
                    }

                }

Answers

  • BelortaBelorta Posts: 13Questions: 3Answers: 0

    Additional question about the onPageDisplay method: is it possible that the bootstrap4 theme is ignored with this? For example: the input elements don't have the "form-control" class. Without the display option in the initialisation of the editor, they do have that class...

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    What is onPageDisplay? That isn't a DataTables event or method. Is something else triggering that?

    Regarding the double Ajax from the Select2 field - no I wouldn't expect to see a double request and I've not been able to reproduce that there. If you put a break point in the plug-in at the Ajax request, it might be possible to determine what is kicking it off each time.

    Thanks,
    Allan

  • BelortaBelorta Posts: 13Questions: 3Answers: 0

    I got the onPageDisplay function from https://editor.datatables.net/plug-ins/display-controller/editor.onPage ...

    The double ajax call: I'll try to debug it a bit more and keep you informed...

  • BelortaBelorta Posts: 13Questions: 3Answers: 0

    About the doubje ajax call:while debugging, I found the following piece of code in dataTables.editor.js in the create function:

        // Set the default for the fields
        $.each( fields, function ( name, field ) {
            field.multiReset();
    
            // Set a value marker for each multi, so the field
            // knows what the id's are (ints in this case)
            for ( var i=0 ; i<count ; i++ ) {
                field.multiSet( i, field.def() );
            }
    
            field.set( field.def() );
        } );
    

    For each field, the ajax call (in editor.select2.js) is called once from the field.multiSet function, and once from the field.set function. Does this help you?

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin

    Yes, thank you. I'm not sure why I'm not seeing it, but that gives me somewhere to start experimenting. I'll get back to you once I've dug into it.

    Allan

  • BelortaBelorta Posts: 13Questions: 3Answers: 0

    Hey Allan,

    Any news about the double ajax queries, and the missing bootstrap4-classes?

    Thanks!

    Tom

This discussion has been closed.