budibase icon indicating copy to clipboard operation
budibase copied to clipboard

Form Field `On Change` will not be emitted after the value changed by `Update Field Value` action

Open taoyuan opened this issue 3 years ago • 7 comments
trafficstars

Hosting

  • Self
    • Method: docker compose
    • Budibase Version: 1.1.4

Describe the bug The On Change handler of form field component works well if the value has been changed by manual. but it will be not emitted when we changed the value from some Update Filed Value action

To Reproduce Steps to reproduce the behavior: In any empty screen:

  1. Add a Form
  2. Add a Text Field in the form
  3. Add a Update State action to set any state in On Change of Text Field
  4. Add a Button in the from
  5. Add a Update Field Value for the buttom and udpate the Text Field value to any other value.
  6. Find the State should be updated by step 3 In DevTools

Expected behavior The value of state should be updated. But it is empty

Screenshots image

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome, Safari

taoyuan avatar Jul 15 '22 03:07 taoyuan

Hey @taoyuan. This was a design decision, so I'm going to mark this as a feature request. I deliberately did not make "update field value" actions trigger other "on change" field handlers as I was worried about creating endless update loops, depending on how you had configured your settings. At the minute it explicitly only reacts to changes by the user.

If this is something you need and other people feel the same then we could look at adding this, but we would have to be careful so that people don't brick their apps by designing endless loops.

aptkingston avatar Jul 15 '22 11:07 aptkingston

@aptkingston Got it. In addition, can we reference the same or other state value in the Update State action, for example,

  1. State.items has been set as [{name: 'Tom'}]
  2. Set State.items to add some other items in Update State action like:
    return [...$("State.items), {name: 'Jerry'}];
    

It seems that we can not retrieve any state value in Update State action.

taoyuan avatar Jul 15 '22 13:07 taoyuan

@aptkingston Got it. In addition, can we reference the same or other state value in the Update State action, for example,

1. `State.items` has been set as `[{name: 'Tom'}]`

2. Set `State.items` to add some other items in `Update State` action like:
   ```js
   return [...$("State.items), {name: 'Jerry'}];
   ```

It seems that we can not retrieve any state value in Update State action.

I'll have a look at this - it should be possible to do that.

aptkingston avatar Jul 15 '22 13:07 aptkingston

@aptkingston After a deeper investigation, I found that the state value can be retreved by state.items. It's just the case of the first letter of the state. And the context to resolve the script is here: https://github.com/Budibase/budibase/blob/16dc6403e32a085e54435d246166f15df5d7202c/packages/client/src/utils/buttonActions.js#L362-L371

Was it designed this way? Or will it be changed in the future?

By the way, perhaps this project is the best looking and most promising low-code project of its kind I've found so far, it exceeds my expectations in some ways and it definitely qualifies as a great project.

taoyuan avatar Jul 16 '22 03:07 taoyuan

@aptkingston After a deeper investigation, I found that the state value can be retreved by state.items. It's just the case of the first letter of the state. And the context to resolve the script is here:

https://github.com/Budibase/budibase/blob/16dc6403e32a085e54435d246166f15df5d7202c/packages/client/src/utils/buttonActions.js#L362-L371

Was it designed this way? Or will it be changed in the future?

By the way, perhaps this project is the best looking and most promising low-code project of its kind I've found so far, it exceeds my expectations in some ways and it definitely qualifies as a great project.

Thanks for the extra info! If it works with lowercase state but not State, then it means the transformation must not be working. When you save bindings, we transform them from "readable" bindings into "runtime" bindings - which involves transforming component names into IDs and transforming other binding categories (like "State") into their runtime keys ("state" in this case). That particular JS binding must not be transforming correctly. That will save me some time while looking at this - thanks!

aptkingston avatar Jul 17 '22 10:07 aptkingston

@aptkingston Glad to be able to help. 😄

taoyuan avatar Jul 18 '22 07:07 taoyuan

This issue has been automatically marked as stale because it has not had recent activity.

stale[bot] avatar Sep 21 '22 04:09 stale[bot]