How do you two-way bind an integer to an input field in Flex/FB4? is_admin is an integer :
<s:TextInput id="textUserIsAdmin" text="@{user.is_admin}" width="5"/>
I receive:
1067: Implicit coercion of a value of type String to an unrelated type int.
Is there a different input type, or do I have to bind a different way?
Short answer, you can't do 2 way binding when trying to change the very nature of the object you're binding. They have to be the same or it won't work. With that said, there is a workaround:
<s:TextInput id="textUserIsAdmin" text="{user.is_admin}" restrict="0-9" change="user.is_admin = int(textUserIsAdmin.text)"/>
As you can see here, I'm binding the original value from the model, but then when the user types something the change event is dispatched and the TextInput value is casted and saved. I also added a 'restrict' so that only numbers can be typed in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With