Pre-populate an edit forn for editor.create()
Pre-populate an edit forn for editor.create()
obrienj
Posts: 93Questions: 38Answers: 0
I am planning to provide a "copy" button to the right of every row on the list screen. ("edit" and "delete" are a;ready there).
What "copy" is to do is create a new row with the data from the row where the "copy" button was clicked.
So what is the best solution to bring up the "create" editor window with the data pre-populated from the existing row?
Once the "create" editor window is displayed, all else will be as it is for my current "create" editor window.
Regards,
Jim
This discussion has been closed.
Answers
Hi Jim,
It sounds like this example is what you are looking for.
Allan
No need to show the Editor window to the user I guess. I mean if it is a simple copy?!
I do something similar: Read data from a cookie fill an Editor instance invisible for the user and submit the data.
So you would take the values from the copied record by selecting the record once the button is being clicked. Fill the Editor instance subsequently with the selected data and submit.
This is part of my code for illustration. Since this Editor instance is never shown to the user it doesn't need any formatting or labels etc.
Of course you can also show it to the user and ask for manual submission. Another example also based on a cookie.. But it is more work because you have to worry about Editor titles, buttons, language and what have you ...
@allan: that is certainly more elegant than my stuff
rf1234: My thanks for your input.
allan: My requirement is that I pre-populate some fields in the new edit window from the columns of the selected row in the datatables list.
The user is required (1) to complete the rest of the fields or (2) change the copied ones in the new row via the edit window.
I can't tell from a quick look, but does the example you pointed to allow for that or is the example a "blind" copy?
Regards,
Jim
My second example does exactly that. Some, but not all fields are pre-populated, the missing fields can be completed and all fields can be changed by the user.
The example I linked to will copy the data from the selected row for all fields. But you could use the method @rf1234 highlighted, which is just to copy the values you want, if that is how you would prefer to do it.
Allan
This is my solution for a joined table situation where I need the user to make a new record but based on a very similar existing record, just saving would cause a unique key error on the database so the user is reminded that something must change:
Note: that the table id #mytable is reference inside the function also apart from the jquery select.
The inline button in the first column in the table definition is as follows:
The table column is as follows, remember to stop _search _an _order _on null data:
It could very likely be neater but it works.
Allan has the following simpler solution But I need the inline buttons:
https://editor.datatables.net/examples/api/duplicateButton.html
Mark