Skip to main content
February 7, 2019
Question

Is there a way to wait for blur on field before continuing loop?

  • February 7, 2019
  • 1 reply
  • 397 views

I'm trying to program a button to check required fields in a form. The goal is to walk the user through the fields that need attention. Right now it jumps to the field and highlights it. I want it to wait for the user to enter data before removing the highlight and jumping to the next field. Can someone show me a way to implement this?

for (var i = 0; i < this.numFields; i++) {

    var f = this.getField(this.getNthFieldName(i));

   

    if (f.type != "button" && f.required && f.value == "") {

        f.setFocus();

        f.fillColor = color.yellow;

        // Wait for user to enter something in f

        f.fillColor = color.transparent;

    }

}

This topic has been closed for replies.

1 reply

Legend
February 7, 2019

A script can't loop until the user does something, because the user can't do anything until your script finishes. And a script can't wait for events. What you have to do is divide your processing up into pieces that are triggered by different events, with global variables to control the current state.  Or, less ambitious, expect the user to check again.

try67
Community Expert
Community Expert
February 7, 2019

It can, actually, using a time-out, but that's not a good way of doing things. It's much easier to use the other field's OnBlur event directly for it.