Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex - How to bind (two-way) an integer to a TextInput Field

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?

like image 999
Scott Szretter Avatar asked Apr 12 '11 00:04

Scott Szretter


1 Answers

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.

like image 91
J_A_X Avatar answered Nov 08 '22 18:11

J_A_X