Skip to main content
Inspiring
Sep 1, 2021 8:18 AM UTC
Solved

How to refresh textfield to be blank after click any button?

As title

    Participating Frequently
    Sep 2, 2021 4:05 AM UTC

    Here is a simple code snippet that should help you achieve this functionality. As mentioned by other practitioners, you set the value of your text input to null in the button's saveInto. 

    a!localVariables(
      local!text,
      {
        a!textField(
          label: "Input",
          value: local!text,
          saveInto: local!text
        ),
        a!buttonArrayLayout(
          buttons: a!buttonWidget(
            label: "REFRESH INPUT FIELD",
            saveInto: { a!save(local!text, null()) }
          )
        )
      }
    )

    12 replies

    stefanhelzle0001
    Brainy
    Sep 1, 2021 8:25 AM UTC

    The value a field shows is stored in a local variable or rule input. To blank the field you need to modify the underlying value using a saveInto.

    Inspiring
    Sep 1, 2021 9:02 AM UTC

    do you mean like saveInto:{ri!input,

    a!save(),a!save()

    }?

    harshas2775
    Brainy
    Sep 1, 2021 8:32 AM UTC

    If for example, you are saving value of the textfield in variable ri!inputText, then within the buttons' saveInto do a!save(ri!nputText,""). now whenever you click on any such button, ri!inputText will become blank.

    Happy to help. Even happier to optimize.
    Inspiring
    Sep 1, 2021 10:26 AM UTC

    but this way may cause ri!inputvalue becomes empty to the database right? I just want it to be saved rightly with value plus the textfield to be blank

    Participating Frequently
    Sep 2, 2021 4:05 AM UTC

    Here is a simple code snippet that should help you achieve this functionality. As mentioned by other practitioners, you set the value of your text input to null in the button's saveInto. 

    a!localVariables(
      local!text,
      {
        a!textField(
          label: "Input",
          value: local!text,
          saveInto: local!text
        ),
        a!buttonArrayLayout(
          buttons: a!buttonWidget(
            label: "REFRESH INPUT FIELD",
            saveInto: { a!save(local!text, null()) }
          )
        )
      }
    )

    Inspiring
    Sep 2, 2021 5:07 AM UTC

    You are right!