Leave the editor window open after creating a row and do not reset the form

Leave the editor window open after creating a row and do not reset the form

av-technikav-technik Posts: 2Questions: 1Answers: 0

Hello,

I would like to have the possibility to insert several entries with similar content one after the other.
For this I wanted to replace the "Create" button with two buttons: "Create" and "Create and close".
The "Create" button should create an entry but leave the form open so that I can adjust the contents of the form to create another entry.
However, with my current code there is still the problem that the form is reset after creating. Is there a way that this does not happen?

new $.fn.dataTable.Buttons(table, [
    {
        extend: 'create',
        editor: editor,
        formButtons: [
            {
                text: 'Create and close',
                className: 'btn-primary',
                action: function () {
                    this.submit();
                },
            },
            {
                text: 'Create',
                className: 'btn-secondary',
                action: function () {
                    const that = this;

                    this.submit(function () {
                        that.create();
                    }, null, null, false);
                },
            },
        ],
    },
    { extend: 'edit',   editor: editor },
    { extend: 'remove', editor: editor },
]);

Answers

  • allanallan Posts: 61,765Questions: 1Answers: 10,111 Site admin
    edited June 2023

    create() will clear out the form values and set them to the defined default (or empty if no value defined). This is by design.

    If you want to keep the previous values, you could copy them and then apply them back - e.g.:

    let values = this.val();
    this.submit(
      () => {
        this.create();
        this.val(values);
      },
      null,
      null,
      false
    );
    

    Allan

  • av-technikav-technik Posts: 2Questions: 1Answers: 0

    Unfortunately, this code still resets the form. I also tried to chain the two functions "create" and "val", here unfortunately the same result.
    Also trying to put the val function into a setTimeout didn't work (but I wouldn't prefer that anyway).

Sign In or Register to comment.