Hi,
On Thu, May 28, 2009 at 1:45 PM, luvfotography <
[email protected]> wrote:
> How do I get databinding to work in textinput?
>
I think you have the idea of databinding a little backwards. Basically, the
bound variable ('userName' in your example) is used to bring data *in*.
In other words, when you have an element like:
<mx:TextInput x="46" y="42" id="myName_ti" text="{userName}"/>
... you're saying, "I have a variable called 'userName,' and I want the
contents of that variable to be displayed in my text input."
So, for instance, if this text input were in an edit form, 'userName' might
represent data coming from a database, which is being placed in the form for
possible editing.
It doesn't mean that whatever is placed in the text input will be injected
into the 'userName' variable. Again, let's say you're pulling a user's
record from a database for editing, and placed the user's data into bound
variables -- one of which is 'userName.'
So the text input would display the current, existing value of 'userName.'
But if you then want to use the edited value, you have to pull it out.
Because what is typed into the text input is accessed through a different
variable -- in this case, 'myName_ti.text' -- not 'userName.' The latter is
simply what came in, not what's going out.
Now if you wanted to have a different MXML element bound to the value of the
text input, you could.
<mx:Button label="{myName_ti.text}" />
... and whatever is typed into the text input will appear on the button.
But if you want to place the text content back into your 'userName'
variable, you'll need to put it there through an event.
You could use an onchange event in the text input to fire a function that
would place the myName.text into userName. But if you did that, you'd create
a circular binding which probably wouldn't be good.
Assuming this is a standard form-like application, you might have a Save
button with a click event. In the click handler function, you'd validate the
form input and place the contents of the form fields into a value object, or
various variables, then pass those to whatever service actually saves stuff
to the database.
--
Thanks,
Tom
Tom McNeer
MediumCool
http://www.mediumcool.com
1735 Johnson Road NE
Atlanta, GA 30306
404.589.0560