How to get contents of one field into another and edit it

Tap Forms – Organizer Database App for Mac, iPhone, and iPad Forums Using Tap Forms How to get contents of one field into another and edit it

Viewing 6 reply threads
  • Author
    Posts
  • January 9, 2019 at 1:54 AM #33337

    Victor Warner
    Participant

    In a form I have two number fields:

    1. Time Spent (with number format set to Time (HH:MM));and
    2. Time Charged For.

    For the second field (Time Charged For):

    (a) I would like to show the value entered into the first (Time Spent); and
    (b) be able to change the value if necessary.

    For example,

    If I enter 00:12 in Time Spent, that value is automatically displayed in Time Charged For, but I can then amend 00:12 to 00:09.

    (a) is the easy part (using a Calculation field type), but a Calculation field type is not editable.

    Is it possible to do this with Tap Forms?

    January 9, 2019 at 1:55 PM #33344

    Brendan
    Keymaster

    Hi Victor,

    Yes. You can do this with a Script field.

    In a Script field when you use the record.getFieldValue(field_id) function, Tap Forms begins watching that field for any changes made to it. It executes the script if the value of that field changes.

    So by adding a Script field, you could have Tap Forms copy the value from your Time Spent field into your Time Charged field. Now normally a Script field will display its contents in your form, but recently I added a Hide field function to Tap Forms 5.3 which will let you hide any field. So you could have this hidden Script field that’s just watching what’s going on with your form and running automatically when fields the script is watching change.

    Thanks!

    Brendan

    January 9, 2019 at 2:05 PM #33346

    Brendan
    Keymaster

    Oh, and to have Tap Forms copy the value to another field, you would do this:

    var time_spent_id = 'fld....';
    var timeSpent = record.getFieldValue(time_spent_id);
    var time_charged_id = 'fld....';
    record.setFieldValue(time_charged_id, timeSpent);
    form.saveAllChanges()
    January 10, 2019 at 2:51 AM #33351

    Victor Warner
    Participant

    Brendan,

    Thank you for the explanation.

    I have tried to follow the approach you outlined. But it appears not to work: the script field and the Time Charge For fields are not updated.

    I created:

    1. Time spent Field = type: number
    2. Time spent to time charged for Field = type: script.
    3. Time charged for Field = type: number.

    The Time spent to time charged for Field only shows a “1” regardless of what I put in the Time spent Field and the Time charged for Field is not updated.

    Attached is the Form. Could you let me know where I have gone wrong?

    Attachments:
    You must be logged in to view attached files.
    January 10, 2019 at 3:16 AM #33353

    Brendan
    Keymaster

    Hi Victor,

    You put quotes around one of the variable names:

    var timeSpent = record.getFieldValue('time_spent_id');

    That’s wrong because it treats the text 'time_spent_it' as the value instead of using time_spent_id as the variable to get the value from.

    So it should be:

    var timeSpent = record.getFieldValue(time_spent_id);

    So just remove the quotes and it will work.

    January 10, 2019 at 3:21 AM #33354

    Victor Warner
    Participant

    Brendan,

    Thank you very much! Problem solved.

    I will hide the script field (as you have suggested), but just to know for the future, will that script field always show a ‘1’ regardless of what is in the other fields?

    January 10, 2019 at 3:30 AM #33355

    Brendan
    Keymaster

    Yes. The 1 is just that it was successfully ran. You can have it return something else if you like.

Viewing 6 reply threads

You must be logged in to reply to this topic.