Multiple data entries

Multiple data entries

mccloudmccloud Posts: 35Questions: 15Answers: 2

When I use the "create new entry" for data input, I would like to open a new input form as soon as I submit the latter. This would allow for a more rapid input of data when I have multiple data entries.
Are there any examples that already show this?

Answers

  • allanallan Posts: 63,489Questions: 1Answers: 10,468 Site admin

    There aren't any examples of that exactly, but you could do it in a number of different ways:

    1. Use the formButtons option of the create button that will submit the form and then create a new one in the submit callback.
    2. Similar to the above, use a custom button (rather than create) that will call the create() method and assign a set of form buttons (buttons()) that will call the submit() method to submit the form and then create() again to create a new form.
    3. Listen for the submitComplete event when creating a new entry and then call create() when that event happens.

    Allan

  • mccloudmccloud Posts: 35Questions: 15Answers: 2

    Still a little unsure of how I implement this. If I go with your suggested option 1, it should give me a create button with the CREATE Entry Form, that when pressed will
    1. Submit the current input of the form
    2. Produce another CREATE Entry Form.
    I have experimented with a CANCEL button, which works but cannot see how I embed the create function.
    My current code looks like this:

    new $.fn.dataTable.Buttons( table,
     [
            { extend: "create", editor: editor,
    
    formButtons: [
                        'Create',
                        { label: 'Cancel', fn: function () { this.close(); } }
                    ] 
     },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor },
    {
                    extend: "selectedSingle",
                    text: 'Duplicate',
                    action: function ( e, dt, node, config ) {
                        // Place the selected row into edit mode (but hidden),
                        // then get the values for all fields in the form
                        var values = editor.edit(
                                table.row( { selected: true } ).index(),
                                false
                            )
                            .val();
     
                        // Create a new entry (discarding the previous edit) and
                        // set the values from the read values
                        editor
                            .create( {
                                title: 'Duplicate record',
                                buttons: 'Create from existing'
                            } )
                            .set( values );
                    }
                },
            {
                    extend: 'collection',
                    text: 'Export',
                    buttons: [
                        'copy',
                        'excel',
                        'csv',
                        'pdf',
                        'print'
                    ]
                }
     
        ] );
        table.buttons().container()
            .appendTo( $('.col-sm-6:eq(0)', table.table().container() ) );
    } );
    
  • allanallan Posts: 63,489Questions: 1Answers: 10,468 Site admin

    Looks like you are heading down the correct track there. Rather than 'Create', you would specify a button using the object syntax (like you do with the following button) and have the function execute submit(), which accepts a callback function would in turn would call create().

    Allan

This discussion has been closed.