Tap Forms – Organizer Database App for Mac, iPhone, and iPad › Forums › Script Talk › Scripted fields in Link-to-Form situations
- This topic has 3 replies, 2 voices, and was last updated 5 years, 1 month ago by Martin Inchley.
-
AuthorPosts
-
November 23, 2019 at 5:18 PM #38253
Martin InchleyParticipantI have a checkbox field “Paid”, and a date field “Payment Date”, with their interactions controlled by two script fields. Checking or unchecking “Paid” enters the current date in “Payment Date”, or empties it. Manually entering a date in “Payment Date” checks “Paid”. Deleting the date unchecks “Paid”. Editing the date leaves it alone.
Everything works fine on their own form. Issues arise when I access them through a Link-to-Form field in another form. Some of the behaviour is consistent, some not. One particular oddity is this:
Accessing these records via the Link-to-Form field, editing the date field results in the checkbox being unchecked, which shouldn’t happen. But when I go to the native form I find that the checkbox is still checked. Back to the linked form – the box is certainly unchecked there.
So my investigation of how to get the scripting to work across forms is hampered by this anomaly. Is the box checked or not? I’d appreciate some advice on how to approach this problem.
Here are the scripts from the control fields, in case they shed any light on things:
//Responds to the "Paid" checkbox field being toggled, //by setting or emptying the Payment Date field var paid_id = 'fld-4f9f9ac525964be99ca478bdaee47144'; var paid = record.getFieldValue(paid_id); var thisDate = new Date(); // put the current date into <thisdate> if (paid) { // Use a special version of "setFieldValue" to prevent triggering the Toggle script record.setFieldValue('fld-cf95ec11043d4d2b8dc51d2ab93f177b', thisDate, false); } else { record.setFieldValue('fld-cf95ec11043d4d2b8dc51d2ab93f177b', "", false); }
//Responds to the "Payment Date" field getting an entry or being emptied, //by toggling the "Paid" checkbox field var payment_date_id = 'fld-cf95ec11043d4d2b8dc51d2ab93f177b'; var payment_date = record.getFieldValue(payment_date_id); if (payment_date) { record.setFieldValue('fld-4f9f9ac525964be99ca478bdaee47144', "true", false); } else { record.setFieldValue('fld-4f9f9ac525964be99ca478bdaee47144', "false", false); }
Any observations very welcome. And, just to note, clicking the refresh button seems to make no difference at any point.
November 23, 2019 at 10:57 PM #38257
Sam MoffattParticipantI’ve noticed that checkboxes seem a little finnicky at times and the only way to get them to re-read properly generally seems to be to go to another record and back again. I’ve not looked as close to ones in Link to Form state, I’ve had quirks happen even in a top level form.
There are two refresh buttons by the way, one under the record listing and one under the main form. Generally if a record isn’t displaying correctly, you want the one under the layout not the under under the list. That said when I have seen this behaviour, I think I’ve also tried refresh and found it wanting.
November 24, 2019 at 9:30 AM #38266
Martin InchleyParticipantHm…
Clicking to another record – in either the main form or the Link-to-Form field – makes no difference.
I’ve written a script to present the info in the console – still the checkbox stays unchecked. I’ve checked the real status of the checkbox field with a calculation field – it agrees with the script result in the console in showing that the checkbox value is true / 1, even though the checkbox is not displaying that in the Link-to-Form field.
And then…
Playing with the LtF field, I removed certain fields from showing. When I saved that, TF crashed and quit (I’m used to that – hopefully the next release will have fixed it). When I re-started and went to the native form (not the linked one with the LtF field), the scripts (in my first post above) for setting the date and toggling the checkbox no longer worked. I did a proper clean re-start – no effect.
What got them working again was bringing up the console. As soon as I did that, they were fine. Grrrr…
So I’m less than happy and, I’m afraid, beginning to lose confidence in the system as a solution for a target user who just needs everything to work. Financial details are a sensitive area…
November 24, 2019 at 9:55 AM #38269
Martin InchleyParticipantOK, I have some progress – though not an answer for why the scripts suddenly stopped working.
The second of the two scripts above toggles the checkbox if the Payment Date field is filled or emptied. I’ve been treating the checkbox field as a Boolean and assuming that using True/False or 1/0 was immaterial.
But if I use “1” and “0” for the value to be inserted, rather than “True” or “False”, then the checkbox responds correctly in the LtF field on the linked form.
I created a new check mark field and used a script to show its value. Before any action, the console reported its value as “False”. But checking it gave a value of “1”. Unchecking it gave “0”. Thereafter it stuck with 1 and 0.
Since my scripts worked initially on their own form, it seems that these checkbox fields will normally work OK with “True” and “False”. But (so far), they need to be using 1 and 0 to be consistent within my LtF field. I’ve tested them both with and without quote marks around the digit – both work fine.
-
AuthorPosts
You must be logged in to reply to this topic.