Is it possible to have an alert pop up when someone clicks the Save as Copy button? I would like to have them accept the alert dialog before the duplication occurs.
Thank you...
How to add and Alert Message on "Save as Copy"
Re: How to add and Alert Message on "Save as Copy"
Hi,
what about this javascript code, which shows a browser-built-in confirmation prompt before copying the record.
Code
(1) For re-usability, the following javascript-function should be put in a common, shared file, for example in hooks/header-extras.php.
(2) Put the following line into the javascript-hooks-file for your table's detail view:
That's it. You can customize the prompt text in the first parameter.
Result
Note the "..." text which has been appended to the button-text. This is a widely used method for indicating to the user that there is a prompt before execution.
Prompt
The record will be inserted (as copy) only if you click OK.
The code keeps the icon, appends "...", keeps form-validation and only applies to "copy" action (for existing records), not to "insert" action (for new records).
what about this javascript code, which shows a browser-built-in confirmation prompt before copying the record.
Code
(1) For re-usability, the following javascript-function should be put in a common, shared file, for example in hooks/header-extras.php.
Code: Select all
// file: hooks/header-extras.php
<script>
function confirmCopy(prompt = "Are your sure?") {
let tn = AppGini.currentTableName();
let pk = jQuery(`input[name="SelectedID"]`).val();
let btn = jQuery("#insert").attr("data-prompt", prompt);
let ico = btn.find("i.glyphicon").clone();
if (tn && btn.length && pk) btn.attr("onclick", `return ${tn}_validateData() && confirm(this.getAttribute('data-prompt'))`).text(btn.text() + "...").prepend(ico);
}
</script>
Code: Select all
// file: hooks/TABLENAME-dv.js
confirmCopy("Do you really want to insert a copy?");
Result
Note the "..." text which has been appended to the button-text. This is a widely used method for indicating to the user that there is a prompt before execution.
Prompt
The record will be inserted (as copy) only if you click OK.
The code keeps the icon, appends "...", keeps form-validation and only applies to "copy" action (for existing records), not to "insert" action (for new records).
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: How to add and Alert Message on "Save as Copy"
Thanks Jan. I was looking for this for a while and found it here.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.