Save as a copy function

Please report bugs and any annoyances here. Kindly include all possible details: steps to reproduce, expected result, actual result, screenshots, ... etc.
Post Reply
Alisson
Veteran Member
Posts: 81
Joined: 2017-02-25 20:32

Save as a copy function

Post by Alisson » 2019-11-29 21:21

HI, I've noticed that when using the SAVE AS A COPY button, most of the fields that have the readonly checkbox marked in appgini are not copied to the new row. Is this the way that it's supposed to work? if yes, is there a way to have the values with readonly duplicated as well?

Thanks.

Alisson
Veteran Member
Posts: 81
Joined: 2017-02-25 20:32

Re: Save as a copy function

Post by Alisson » 2019-12-02 18:22

It seems that since appgini 5.8x there was a new feature added to find the first "focusable" item on the page.
In my case the first field is a lookup-field, so I cannot click the dropdown before the page add focus on it.

Our Appgini Super hero "jsetzer", as always, found a solution and it works fine. So if someone else is having the same problem, here is the solution he gave me:
If you need to disable the new focus-finding function, please try to put this code in your TABLENAME-dv.js:

AppGini.focusFirstFormElement = function() { /*noop*/ };

This will just replace the existing (new since 5.8x) function by a function doing just nothing.

Maybe this will help on detail view forms where you need the lookup at first position.

User avatar
a.gneady
Site Admin
Posts: 1281
Joined: 2012-09-27 14:46
Contact:

Re: Save as a copy function

Post by a.gneady » 2019-12-04 16:29

Alisson wrote:
2019-11-29 21:21
HI, I've noticed that when using the SAVE AS A COPY button, most of the fields that have the readonly checkbox marked in appgini are not copied to the new row. Is this the way that it's supposed to work? if yes, is there a way to have the values with readonly duplicated as well?

Thanks.
I inspected the issue, and was able to reproduce it indeed. It's actually intended to behave this way indeed. When copying a record (and its child records), AppGini does this by copying the editable values of the source record to the new record, leaving read-only fields to be filled automatically if they have default values, or to be filled by a third-party app if applicable. This mimics the exact behavior of adding a new record.

If you'd like to copy read-only fields to the new record, you can do so using the tablename_after_insert hook ... For example, assuming the table has a read-only field named 'readonly_field', you can add code like this to copy its value from the source record:

Code: Select all

$source_id = makeSafe($_REQUEST['SelectedID']);
if($source_id) { // copy read-only field only if this record is a copy of another one ...
    $source_val = sqlValue("SELECT `readonly_field` FROM `tablename` WHERE `id`='{$source_id}'");
    update('tablename', ['readonly_field' => $source_val], ['id' => $data['selectedID']]);
}
In the above code, replace 'tablename' with the actual table name, 'id' with the name of the primary key field, and 'readonly_field' with the name of the read-only field.
:idea: AppGini plugins to add more power to your apps:
  • DataTalk is an innovative AppGini plugin based on ChatGPT that allows you to interact with your AppGini database using natural language questions, without writing any SQL. Check the demo video
  • Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
  • Check our other plugins and get a generous discount of up to 30% when buying 2 or more plugins.

User avatar
zibrahim
Veteran Member
Posts: 137
Joined: 2020-01-28 18:30
Location: Malaysia

Re: Save as a copy function

Post by zibrahim » 2021-08-13 05:14

Thanks Ahmed for the codes.
Actually, I was looking for something like this, to prevent from copying the file attachment (data) when saving as copy.
I modified the code to the following

Code: Select all

// code location : tablename_after_insert hook
// prevent copying file attachment (data) from being copied when Save As Copy
	$source_id = makeSafe($_REQUEST['SelectedID']);
	if ($source_id) { // execute if this record is a copy of another one ...
		update('tablename', ['file_field' => NULL], ['id' => $data['selectedID']]);
	}
In the above code, replace 'tablename' with the actual table name, 'id' with the name of the primary key field, and 'file_field' with the name of the file attachment field.
Hope this will help someone .... stay safe.
Zala.
Appgini 24.10.1579, MacOS 14.3.1 Windows 11 on Parallels.

Post Reply