No internet connection
  1. Home
  2. How to

Auto Fill (Editable) Text Prompt

By Iain Anderson @Iain_Anderson
    2023-08-08 10:02:06.370Z

    Hi there,

    I'm working on a script that will prompt the user for input but will auto fill with the output of another function in the script.

    Is there some clever code to make a popupText box auto fill with data from a variable? I'd also like to be able to edit that auto fill data before confirming entry.

    var adrLine = sf.interaction.popupText({
            title: 'ADR Line'
        }).text;
    

    Many thanks,

    Iain

    • 2 replies
    1. @Iain_Anderson, to be able to edit an auto-filled string in a prompt I suggest using displayDialog.

      Here's a simple example:

      function getAdr() {
          return "ADR Line"
      }
      
      const adr = getAdr();
      
      const adrLine = sf.interaction.displayDialog({
          prompt: "Enter ADR Line",
          defaultAnswer: adr, // This is the auto-fill
      }).text
      

      Alternatively, you can pass the function directly to popupText if it makes sense to do so in the context of your script:

      function getAdr() {
          return "ADR Line"
      }
      
      const adrLine = sf.interaction.displayDialog({
          prompt: "Enter ADR Line",
          defaultAnswer: getAdr(),
      }).text
      

      Hope that helps!

      1. I
        In reply toIain_Anderson:
        Iain Anderson @Iain_Anderson
          2023-08-09 10:11:08.045Z

          Awesome work. Love it. Thanks!