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
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
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.:
Allan
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).
@allan Any update on this?
Are you inserting same values for every entry?
@Aryan1703
Almost, I would like to enter all values once and create the entry. Then I want to be able to adjust individual values and save them again.
The project is a hardware inventory. For example, I would like to add 10 monitors. All data is basically identical, only the inventory number and serial number are different. I would just change these briefly and create the next entry.
If you would like to create same entries You can optionally pass the first parameter of .create() as a row count to make it create multiple new rows. So: in my case I wanted to create 15 duplicated entries.