Editor Multiset On PreSubmit

Editor Multiset On PreSubmit

Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2
edited December 2018 in Editor

I am wondering if it is possible to have a single editor create form which when submitted can be sent to the database as separate records.

The overall aim was to be able to split a comma separated list of email addresses, which will be entered in a single field, and enter multiple records, dependent on how many addresses where entered, with the same information being added for each new row except in the case of the email address which will be different each time.

I have played around with initSubmit and preSubmit using the create API but not having much success. This simple example does not work.

        var editor = new $.fn.dataTable.Editor({
            ajax : {
                url : "run_datatable.php",
                type : "POST",
                data : function(d) {
                    d.table = "test",                                                                                                     
                }
            },
            table : '#test',
            fields: [{
                label : "Forename:*",
                name : "forename", 
            }]
        }); 
        editor.on( 'preSubmit', function ( e, data, action ) {

            editor.create( 3, 'Add new record', 'Save' );
            editor.field( 'forename' )
                .multiSet( 0, 'Allan' )
                .multiSet( 1, 'Bob' )
                .multiSet( 2, 'Charlie' ).submit();
    
            return false;
            
        });

I was seeing if I could intercept the forms submission and alter it from a single create to a multi create.

Is this theoretically possible?

Thanks

Chris

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599
    Answer ✓

    Hi @Restful Web Services ,

    Yep, take a look at this. I've reused the Position field as your email - so you can test it by putting commas in that field. It seems to be working how you want it,

    Cheers,

    Colin

  • Restful Web ServicesRestful Web Services Posts: 202Questions: 49Answers: 2

    Hi Colin,

    Wow, fantastic. Thanks for putting together that example, it works exactly as I was intending. I haven't had a chance to implement it with my database yet but it should be perfect.

    Thanks so much for taking the time to put that together.

    Chris

This discussion has been closed.