livecode

How to create a custom dialog box in LiveCode


I have a button. When I clicked that button I want a dialog box to popup with multiple text field and button. I have been looking all around to try to figure out how to do this but I keep on getting more confused. Can anyone help?


Solution

  • The simplest example of a dialog box is this. Make a new substack of your mainstack and call the substack "Dialog". Add a button to the substack, call the button "OK" and give it the following script:

    on mouseUp
      set the dialogData to "OK" 
      close this stack
    end mouseUp
    

    Make another button in your mainstack and give it this script:

    on mouseUp
      go stack "Dialog" as modal
      put the dialogData
    end mouseUp
    

    You now have a dialog window. You can add fields and more buttons to your Dialog stack. For example, you can create a cancel button with the following script:

    on mouseUp
      set the dialogData to "Cancel"
      close this stack
    end mouseUp
    

    and if you have a field, you can change the script of button "OK" into

    on mouseUp
      set the dialogData to fld 1
      close this stack
    end mouseUp