Page 1 of 1

Save as a copy function

Posted: 2019-11-29 21:21
by Alisson
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.

Re: Save as a copy function

Posted: 2019-12-02 18:22
by Alisson
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.

Re: Save as a copy function

Posted: 2019-12-04 16:29
by a.gneady
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.

Re: Save as a copy function

Posted: 2021-08-13 05:14
by zibrahim
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.