Button with Script does not have a visible effect

Tap Forms Database Pro for Mac, iPhone, iPad and Apple Watch › Forums › Using Tap Forms Pro › Button with Script does not have a visible effect

Viewing 2 reply threads
  • Author
    Posts
  • September 25, 2026 at 12:41 PM #54570

    tekl mister
    Participant

    I’ve a simple form with two date fields (start and end) and some other fields. The first date field is populated with the current date. The second date field is empty. And some fields are hidden until the second field contains a date. To make it easier for the user, I’ve added a button to a Universal layout. When I click the button, the date field should be filled with the current date. I use this script for the task:

    function MyScript() {
        var field_id = 'fld-b64c54dfb3de446fbf2b25b203c90104';
        
        record.setFieldValue(field_id, new Date(), true);
        record.refreshCalculations();
        form.saveAllChanges();
        document.saveAllChangesAndRefresh();
        record.refreshCalculations();
        }
    
    MyScript();

    As you can see, I tried a lot to make the button work. But it doesn’t. After clicking, nothing happens. When I click on an empty area of the form, the second date field shos its content. But the hidden fields are still hidden, I’ve to switch layouts or record to let Tap Forms update the screen.

    Is there a way to refresh the view? Or did I something wrong?

    September 25, 2026 at 3:59 PM #54572

    Brendan
    Keymaster

    So you’re using the new Conditional Visibility rules to decide to show or hide a field? I don’t think I tested the condition where the value is changed from within a script. I’ll have to look into that. I had just been focused on when you change values using the user interface.

    Also you should only need a single document.saveAllChangesAndRefresh() at the very end of your script, after you make any changes. So that record.refreshCalculations() should go before the save function call.

    September 27, 2026 at 12:58 PM #54579

    tekl mister
    Participant

    Hi Brendan,

    Yes, you understood that exactly right. Apparently, the buttons still need a little fine-tuning when it comes to refreshing the form.

    I knew that a single saveAllAndRefresh was enough. Those were just remnants of my attempts to somehow force the window contents to redraw.

    Tekl

Viewing 2 reply threads

You must be logged in to reply to this topic.