Reputation: 3998
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?
Upvotes: 9
Views: 5358
Reputation: 5096
EDIT: Making sure I give you the answer you want.
If you want the value of the integer to be in the TextInput and you want to cast the value of the textinput to be in user.is_admin, use the following:
<s:TextInput id="textUserIsAdmin" text="@{user.is_admin.toString()}" change="user.is_admin = int(textUserIsAdmin.text);" width="5" />
Hope this helps.
Upvotes: 0
Reputation: 12847
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.
Upvotes: 16