views:

109

answers:

3

I use several controls with combo boxes and data grids, which I fill using a HTTPService which returns some XML. However in the XML there are some telephone numbers starting with a plus sign (ie. +123456). However in the combo boxes and the data grids the plus sign doesn't show (so it would display as 12345646).

It doesn't matter if I use CDATA or not. When I change the value I saw the following:

  • +123456: shows as "123456"
  • +123+456: shows up correctly
  • +abcdef: shows up correctly
  • +abc456: shows up correctly
  • +123def: shows up correctly
  • +123+def: shows up correctly

So two questions: why does this behaviour occur, and how can I prevent this and show the value correctly?

As requested, sample code. Somewhere in an <mx:Script>-tag:

contactsService.send();

And in the MXML:

<mx:HTTPService id="contactsService" url="http://some/url/" method="GET" useProxy="false"/>
<mx:ComboBox prompt="Select phone number" dataProvider="{contactsService.lastResult.contacts.contact}" labelField="phonenumber" id="contactsComboBox"/>

As you can this is a fairly simple set-up.

A: 

You're probably converting them to Number values somewhere in your code. If you ensure that they are String values instead, the plus should not disappear.

joshtynjala
But wouldn't that throw errors for other numbers (or make them NaN)?
Amarghosh
I don't understand your question. Telephone numbers are not really numeric, so ensuring that they're stored as Strings shouldn't be a problem.
joshtynjala
I import the XML data directly into the DataGrid (see my example above as well). How would I go and define the affected columns as String data instead of Numeric data?
pbean
A: 

I just tried replaciing the Plus sign (+) with %2B and that did it.

Hope it works for you

dele
A: 

Actions script is strongly typed, text is text unless you run a function on it. Numbers are Numbers unless you run a function on them.

That is until you start dealing with XML. e4x is NOT strongly typed, so it will do it's best to figure out the type based on the data that is there.

You can solve your problem by looping through your XML and putting the values into an array with the toString() function. Then use that array to feed your combo box.

invertedSpear