While receiving `TextFieldValue` input, is there a...
# compose-desktop
s
While receiving
TextFieldValue
input, is there a way to specify the type that is expected or is it always expected to be a
string
(
TextFieldValue.text
) For example could i have an arbitrary
KotlinType
that i could use for validation directly?
j
Can you elaborate? I'm not sure I understand what you're asking. If TextFieldValue is always going to be a simple string, you can just grab
textFieldValue.annotatedString.text
and use it as a String. Keep in mind that you'll almost certainly want to retain
selection
and
composition
also in order to preserve editing and IME.
s
I was hoping there would be a way to have arbitrary types such as
Int
Float
etc, that are specified at runtime and could be used to dynamically generate the text fields with “automatic” validation. So for example, if the expected type would be
Int
, there would be away to “validate” i.e only accept
Int
as valid input
these arbitrary types would be of format
KotlinType
or
KType
j
You could easily write a set of widgets that did that in user land. Often, you want to be able to perform more advanced validation like entering a credit card number or telephone number or email address or any other number of validators. We can't possibly provide all validators, so instead we made it possible for users to define their own validators in user land. Hopefully someone in the community can build a library of widgets with the common validators, and we can focus on building features that require intimate knowledge of the internals of Compose thus enabling entirely new classes of functionality that is currently impossible.
👍 1
s
makes total sense, thank you 🙌