cljfx

thom 2021-10-02T18:22:14.013600Z

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).

vlaaad 2021-10-02T21:01:22.013700Z

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

vlaaad 2021-10-02T21:03:29.013900Z

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

vlaaad 2021-10-02T21:05:26.014200Z

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

vlaaad 2021-10-02T21:05:50.014400Z

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

thom 2021-10-02T21:16:16.015400Z

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