edvin / tornadofx

Lightweight JavaFX Framework for Kotlin
Apache License 2.0
3.68k stars 272 forks source link

TextField Binding of Integer Property #184

Closed gtnarg closed 8 years ago

gtnarg commented 8 years ago

textfield( model.myInt )

where model.myInt is an Integer property is not supported whereas the following is:

  textfield(){
        bind( model.myInt )
   }

Is this by design or an oversight?

See full sample below.

Thanks Grant


import javafx.beans.property.SimpleIntegerProperty
import tornadofx.*

class MyView : View("My View") {

    val model = MyPojoModel( MyPojo(1) )

    override val root = stackpane {

        // not supported
        // textfield( model.myInt )

        // works
        textfield(){
            bind( model.myInt )
        }

    }

    class MyPojo( var myInt: Int )

    class MyPojoModel(val mypojo: MyPojo) : ViewModel() {
        val myInt = bind { SimpleIntegerProperty(mypojo.myInt) }
    }

}
edvin commented 8 years ago

It is by design, you must add IntegerStringConverter() as the second parameter. We might be able to support it though, I will check when I get back home tomorrow and let you know :)

bekwam commented 8 years ago

Hi,

For the two-argument function, use NumberStringConverter. javafx.beans.property.IntegerProperty is actually Property rather than Property

    textfield(SimpleIntegerProperty(101), NumberStringConverter())
edvin commented 8 years ago

Yeah, sorry, that's what I meant :) I'm on my phone in Oslo, just winging it :)

edvin commented 8 years ago

This feature is now merged with master. Thanks @bekwam :)