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: 32
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: 32
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: 1041
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: Learn all the tips and tricks of customizing AppGini apps through our online course.
:arrow: Mass Update plugin: Update multiple records at once and improve your workflow efficiency.
:arrow: Summary Reports plugin: Build powerful reports and charts for your AppGini apps.
:arrow: Search Page Maker: Compose user-friendly yet powerful search pages for your AppGini apps.

Post Reply