Script to Collapse Section

Viewing 10 reply threads
  • Author
    Posts
  • December 29, 2022 at 8:34 PM #48521

    Tim H
    Participant

    I a real beginner with scripts in Tap Forms so am finding it difficult to collapse a section based on the contents of a field. Basically I’d like to collapse a section if another field is empty.

    I see from Tap Form’s JavaScript API there is something that looks like it should close a Section Heading type field (field.isCollapsed = true;) but when editing a form script the Section Heading type field I want to control does not appear in the list of Available Fields. I was able to get the field ID from the Fields List but still cannot programmatically collapse the section.

    I’d appreciate any tips on getting this to work. Thanks

    T.

    December 30, 2022 at 1:42 AM #48525

    Brendan
    Keymaster

    Hi Tim,

    This code should do the job:

    function Collapse_Section() {
    	var section_id = 'fld-7f00598612814de980cb7250d8391570';
    	var sectionField = form.getFieldWithId(section_id);
    	sectionField.isCollapsed = !sectionField.isCollapsed;
    }
    
    Collapse_Section();
    December 30, 2022 at 1:42 AM #48526

    Brendan
    Keymaster

    The example above just toggles the section opened and closed each time you run the script. You will probably have different logic.

    December 30, 2022 at 7:09 AM #48527

    Tim H
    Participant

    Hi Brendan,

    I was able to use your bit of code and get the Section to collapse based on whether or not another field was undefined. It works great thank you!

    Now is there a way to get this script to “auto-run”? I’ve saved the script as a “form script” i.e. it’s not a script type field in the form but I have to manually run it each time. Ideally I’d like the script to run each time a different record is displayed i.e. collapsing/un-collapsing the section while browsing records.

    Thanks again for your help.

    T.

    December 30, 2022 at 2:32 PM #48533

    Tim H
    Participant

    Thinking about this a bit more…

    Is there a way to auto-run a script based on a saved search? For example lets say I have saved a search that utilizes a rule that a particular field be non-empty. Additionally I have a saved search with a rule that specifies a field to be empty. Depending on which saved search I’m browsing records with, the script would “fire” either collapsing or expanding the section heading.

    Basically, I’ve got a long default form with a section containing a bunch of fields that I’d prefer not to see (collapse section) unless there is information in one of the fields within the section.

    Thoughts/ideas?

    T.

    December 30, 2022 at 7:14 PM #48535

    Daniel Leu
    Participant

    Idea: how about assigning a keyboard shortcut to a script?

    December 31, 2022 at 6:11 AM #48536

    Tim H
    Participant

    Hi Daniel,

    Thanks for the idea. I looked into it and it’ll work but I’d prefer something more “automatic” while browsing records. I could also create another form with a subset of fields but I’m trying to avoid a bunch of forms that only differ by a few fields. I’m holding out for an “automagic” way to collapse/expand a section. :)

    T.

    December 31, 2022 at 3:34 PM #48541

    Brendan
    Keymaster

    Scripts don’t run when you’re just browsing records. Imagine you had a script that took a long time to execute and you ran it for every record that’s displayed. It would make browsing miserable.

    So there’s no automatic way of triggering a script when clicking on a Saved Search. You would have to refresh the records list which would run every script on every record displayed.

    December 31, 2022 at 4:43 PM #48542

    Tim H
    Participant

    Hi Brendan,

    Understood, hmm how about a feature suggestion. Save the “state” of section(s) collapsed/expanded in the default single-column list view with a saved search. Similar to how Tap Forms saves the column layout in a multi-column list view for each saved search.

    Thanks so much for the help and listening. Tap Forms is a great product that I really enjoy using. It makes keeping track of my data soooo much easier.

    T.

    December 31, 2022 at 4:45 PM #48543

    Tim H
    Participant

    Or, maybe save a specified single-column layout with a saved search.

    T.

    December 31, 2022 at 7:35 PM #48544

    Brendan
    Keymaster

    The isCollapsed state property lives on the field itself, which has no direct relationship to the Saved Search. But perhaps in a future version I could make an association there.

    Happy New Year!

Viewing 10 reply threads

You must be logged in to reply to this topic.