Filling and monitoring text field changes

Hi! I'm failing to prefill and monitor changes of a text field.
My current approach is to prefill the fields with this buttonClickHandler query:

apiFetchQuery.trigger({
  onSuccess: function(data) {
    textInput1.setValue(data.someTextField)
    state1.setValue(false)
  }
})

if state1 is false it means that the data hasn't been changed. To monitor changes in this textfield, I set up an event handler on textInput1 that triggers a query.

state1.setValue(true)

Unfortunately, the buttonClickHandler query triggers the event handler to run after it finished so state1.value returns true. It even is like this if I only run the event handler if {{!buttonClickHandler.isFetching}}.

Is there a best practice to achieve what I'm trying to do?

Any help is much appreciated. Thanks :slight_smile:

I have a form which I track to see if is dirty (a value has changed) and enable a "Save" button if it is. Take a look here

You only have one field, so you could use a simplified version of that pattern. Save the value or textInput1.value to state1 on data refresh, then simply check state1.value === textInput1.value wherever you need to see if it's changed.