Wait for HtmlDialog to close before executing next line

How do I wait for my html window to close, or at least the submit button to have been clicked, before collecting my javascript parameters from the #HtmlDialog?

So I’m currently trying to use:

module DialogBox
  extend self
  def dialogtest_setup
    # html dialog is setup and defined in here
  end

  def show_dialog
    @dialog.show
    # some code here to wait for the box to be closed/submit button to be clicked
      @dialog.add_action_callback("say") { |action_context, param1, param2|
        @param1, @param2 = param1, param2
      }
  end

  def puts_params
    puts @param1
    puts @param2
  end
end

testbox = DialogBox
testbox.dialogtest_setup
testbox.show_dialog
testbox.puts_params

But this returns previous values :roll_eyes:

Any help appreciated!!

OK, I changed the code to make it work as follows:

module DialogBox
  extend self
  def dialogtest_setup
    # html dialog is setup and defined in here
  end

  def show_dialog
    @dialog.show
    @dialog.add_action_callback("say") { |action_context, param1, param2|
      @param1, @param2 = param1, param2
      puts @param1
      puts @param2
    }
  end
end

testbox = DialogBox
testbox.dialogtest_setup
testbox.show_dialog

This works for me, because I will just call the necessary code block within the add_action_callback. However, this may not work for some people…any suggestions on how to wait outside of the module?

Using the callbacks to ensure the dialog has done its thing is the idiomatic way to do it. With async communication there isn’t any better way around it, you have to use chained callbacks like this.

1 Like