Fork me on GitHub
#cljfx
<
2021-10-02
>
thom18:10:14

I've got a TextField with a formatter, which is rendered dynamically, and the specific formatter can change. When this happens I seem to get clojure.lang.ExceptionInfo: Replace forbidden {:old-value :long, :new-value :double}. Am I doing something wrong? It's a child in a list so I assume the instance is being reused and it's difficult to atomically set formatter and value all at once (although I'm using the value key inside the text formatter).

vlaaad21:10:22

Replaces are forbidden in cases where the value is a constructor argument that cannot be changed later, i.e. there is just no way to mutate the object to set the value to a new one

vlaaad21:10:29

Here are the docs for TextFormatter: https://openjfx.io/javadoc/14/javafx.controls/javafx/scene/control/TextFormatter.html As you can see, it has filter as an argument, but no setters to change it afterwards

vlaaad21:10:26

The workaround is to re-create the whole text formatter when you want to change its filter

vlaaad21:10:50

There is an extension lifecycle that does that, described here: https://github.com/cljfx/cljfx/issues/76#issuecomment-645563116

thom21:10:16

Ah, gotcha, that's nice. Thanks for the pointer!