final-form / final-form-calculate

Decorator for calculating field values based on other field values in 🏁 Final Form

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Access previous values

rockingskier opened this issue · comments

commented

Would it be possible to access the previous value of the changed input? This would allow for swapping values around.

For example:

  {
    field: 'opt1',
    updates: {
      opt2: (opt1Value, allValues, prevOpt1Value) => prevOpt1Value
    }
  }

Ehy guys do you still think this is useful?

I created a pr for that (#24), I personally have a particular use case and this is useful form me.

Basically I want to initialize a form with value but since I have some values that on change needs to clear some other I end up having a clean form instead of an initialized one.

Adding previous values I can check if the previous value is undefined and prevent the update to happen, or well return the current value instead.

Let me know

Published fix in v1.3.0.