One more suggestion: The radio group should take o...
# kvision
j
One more suggestion: The radio group should take other objects than only Strings. For example enum values are a typical use case. I understand that the String value is very useful for formatting (without needing a formatter or other callback). But the key could/should by of any type ("T")
r
String value is a requirement of compatibility with Form/FormPanel.
But I've generalized both RadioGroup and RadioGroupInput with GenericRadioGroup<T> and GenericRadioGroupInput<T> classes for usage with any types. RadioGroup now just extends GenericRadioGroup<String>.
👍 1
j
Hey. Currently testing genericRadioGroup. I run into strange problems with a lot of error messages like "Uncaught TypeError: tmp0_subject.equals is not a function". This seems to be thrown in the "toStr" method. I tried several implementations - but the problem seems to be, that the generated code does not find any methods (".name" or ".equals") for my enums. My Kotlin Code (ModuleOrientation is just an enum class)
Copy code
genericRadioGroup(
      options = listOf(
        ModuleOrientation.Vertical to "Vertical",
        ModuleOrientation.Horizontal to "Horizontal"
      ),
      toStr = { moduleOrientation ->
        moduleOrientation.name
      }
    ) {
      label = "Module Orientation"
      value = data.orientation //initial value
    }.subscribe {
      data.orientation = it ?: ModuleOrientation.Vertical
    }
One more thought: We had some problems when getting callbacks from JS with enum types. These seem to be converted to Strings. Maybe it is related to that issue? I will try something
Yes. It is the enums problem. This code works:
Copy code
genericRadioGroup(
      options = listOf(
        ModuleOrientation.Vertical to "Vertical",
        ModuleOrientation.Horizontal to "Horizontal"
      )
    ) {
      label = "Module Orientation"
      value = data.orientation
    }.subscribe {
      it?.let {
        data.orientation = ModuleOrientation.valueOf(it.toString())
      }
    }
r
Have you defined
fromStr
function?
Both are required
j
fromStr is set by default. Which should be good enough
sorry . no
toStr is configured. I will give it a try
r
on the contrary i think
I have tested enums with
fromStr = { MyEnumClass.valueOf(it) }
and the default
toStr
j
Yes. I added these method and now it works as expected.
The error messages have been a bit misleading in my case. Didn't relase there is a fromStr field But works now for me!
👍 1