separating data in an array for display in Flex - actionscript-3

I'm new to flex/flash builder, i need to read in data from a text document, then slice it into pieces i set out in my custom class.
all of this so far worked
var theCustomer:Customer=new Customer(name,address,phoneNo,comment,custNo);
custArray.addItem(theCustomer);
So now what i want to do is display only the name from each entry of the array into a combobox - and then on close it will display all the details into a list box
If i just bind the custArray to the combobox it displays name:address:phoneNo:comment:custNo as i set it out, but like i said i want only the name so how do i separate the name from each Customer entry in the array ??
Any help you be awesome and thanks in advance !!!

If I'm understanding your question correctly, I think you want to set the labelField property on the combobox. This specifies the field in the source data objects to use in the label.
<s:ComboBox dataProvider="{custArray}" labelField="name"/>

The ComboBox has several ways to specify what it should use as the "label" for each item in the dataProvider:
By default, if the elements in the dataProvider has a property named label, and that property contains a String it will display that value.
ComboBox has a labelField property that you can use to tell it where to find the "label" for each item. In your case, you could set the labelField to "name"
ComboBox has a labelFunction property that allows you to use a function (that you write) to specify what text should be displayed for each item.
I suggest using the the labelField, as that seems the most straight forward in this case:
<s:ComboBox dataProvider="{custArray}" labelField="name" />

Related

MvxAutoCompleteTextView setting Text property to SelectedObject ToString()

I am using MvxAutoCompleteTextView (MVVM Cross's custom AutoCompleteTextView) and have the List appearing fine and the ItemTemplate displaying as expected.
When I click on one of the Items in the List the Text property gets set to the full name of the Type of object in the List. For example if the List contained objects of type MyObject in a namespace of MyCompany.MyDept the text property would be set to the string "MyCompany.MyDep.MyObject"
Anyone else ever seen this?
UPDATE
It looks like Android's AutoCompleteTextView prefers just a list of strings as the source of the list.
There is a method in the Android code called ConvertSelectionToStringFormatted but I cannot see how to provide an alternative to that
If you look at my UPDATE in the question you will see that the problem lay with ConvertSelectionToStringFormatted.
I could not see how to easily create a custom version of MvxAutoCompleteTextView with my own implemenation of ConvertSelectionToStringFormatted so I need a different approach.
Android's AutoCompleteTextView was obviously calling ToString on the selected object so I overrode ToString in my object to return a display name that was more useful than "MyCompany.MyDep.MyObject"
I thought I would also include my final axml for the control as that was pretty important
<MvxAutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:hint="Enter drug name..."
local:MvxItemTemplate="#layout/item_myObj"
local:MvxBind="ItemsSource Suggestions;
PartialText SearchTerm;
SelectedObject SelectedObj;" />
Setting completionThreshold was pretty important, when that was not set the control stopped working\searching once I had cleared the box. No matter what I typed after clearing the box (with backspace) it would not autocomplete anymore. Another odd issue when threshold was not set was that the PartialText was binding as an empty string once it went to 1 character! Yes 1 not 0.
Do not make the mistake of binding the Text property of the control. PartialText is the search term leave Text well alone. This caused me lots of odd issues.
Good luck

Can't remove the value entered in the djFilteringSelect dojo control in xPages

I am using the djFilteringSelect control to show values in a dropdown as user type a value.
The lookup and typehead is working fine. The user type a letter and the dropdown allow the user to select a value which is then displayed in the dropdown field.
If the user now decide to remove the value first selected so that the combobox is empty and leave the field, then the first value in the list is now automatically filled in.
The consequence of this is that if the user have added a value there is no way to remove the value and leave the box emtpy.
I am using required=false for both the control and the dojo attribute but it does not seem to help. There are also a few other djFilteringSelect attributes I have tried like "Autocomplete" and "trim" but it does not work
Here is the code
<xe:djFilteringSelect id="test" type="select" store="jsondata" searchAttr="data" required="false" labelType="html" invalidMessage="Not valid">
<xe:this.dojoAttributes>
<xp:dojoAttribute name="required" value="false"></xp:dojoAttribute>
</xe:this.dojoAttributes>
</xe:djFilteringSelect>
Initally the field is not required, but if the user have entered a value it is required.
My question is if there a way to prevent the djFilteringSelect control to always populate the field if I have previously added a value
I found someone who solved this in another stack overflow topic, by creating an empty entry in my data store. but I could not get this to work
Dojo: Select of empty value for FilteringSelect while required=false
I do this quite a lot. Right now I don't have a working sample to show you (since I moved to bootstrap - and have to code the selects by manually adding select2 controls) but something like this should do it...
I add an "empty" value at the top of my select - and that seems to work no matter whether I am using a combobox, djCombobox or combobox with select2 from bootstrap. My markup typically looks like:
<xp:comboBox id="inputLocationSelector" value="#{User.catchListType}" disableClientSideValidation="true">
<xp:selectItem itemLabel="(none)" itemValue=""></xp:selectItem>
<xp:selectItems>
<xp:this.value><![CDATA[${Configuration.meta.listLocationTypeOptions}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
Then you could specify "(none)", "All" or " " for the "not-selected" value depending on your needs.
Validation is a different thing so just specifying "required=false" does not give you the "empty" value.
/John

AS3 Databinding to Specific property at an index in ArrayCollection

I have a situation where I want to use databinding from an ArrayCollection to populate text fields in a Flex view.
The ArrayCollection is populated from an SQL Result object. I store the ArrayColelction in my model class using getters and setters like this:
private var _monthlyData:ArrayCollection;
public function set monthlyData(value:ArrayCollection):void{
_monthlyData = value;
}
[Bindable]
public function get monthlyData():ArrayCollection{
return _monthlyData;
}
I use the monthlyData as a dataprovider for a list etc which works fine. I also need to use properties at certain indexs in this collection as text field strings.
When the text field text properties are set I don’t neccesarily have the monthlyData arrayCollection populated yet.
The text fields are set in another outside class with has a singleton reference to this model so I set the fields like so at the moment:
textField.text = _model.monthlyData.getItemAt(3).Month;
I want to setup binding to the array collection instead of just using this assignment method so that when that item in the array is refreshed or the entire arrayCollection is populated or updated , it will update the textField text.
I’m having trouble getting the binding to work.
I’m using bindageTools at the moment but have been also using the built in as3 BindingUtils to little effect.
I can do the following which sets the initial text property correctly, but it wont update when the ArrayCollection changes:
Bind.fromProperty(_model.monthlyData.getItemAt(3),"Month").toProperty(textField, "text");
So if someone could please point me in the right direction as to which way is best to get the binding going in pure AS3 no MXML, I’d really appreciate it.
Cheers
Marco
From the code you provide, I can see that monthlyData is bindable, which is fine. I'll assume that _model is bindable too.
However the getItemAt() method is not bindable (it will not dispatch propertychange events when items change positions in the collection), hence the text property of the text field will not be updated.
What you can do is something like this:
[Bindable]
public var selectedDate3:MyDate;
<s:TextInput id="myTextInput" text="{selectedDate3.month}" />
or the AS equivalent (why you want to make things hard on yourself is beyond me though)
BindingUtils.bindProperty(myTextInput, "text", selectedDate3, "month");
and then programmatically update selectedDate3:
_model.monthlyData.addEventListener(CollectionEvent.COLLECTION_CHANGE, updateSelected);
private function updateSelected(event:CollectionEvent):void {
selectedDate3 = _model.monthlyData.getItemAt(3);
}
Note that the month property of MyDate must also be bindable.
You mention that these fields are in a VGroup. I'm guessing you want to display a top 3 or something. This is still a list. It would be much easier and cleaner to do this with a List or DataGroup and simply filter the ArrayCollection to only display the first 3 items (or whatever rule for the items to be displayed), or configure the DataGroup to display only three items (it has no scrollbar anyway).

Accessing ListBox selected item via UiApp.getActiveApplication().getElementByID()

Currently I am using UiService to create a form and I uses ListBox, from what I understand to pass a value via handler will be something like e.parameter.[Name of ListBox] to access the selected item.
Does anyone know is it possible to use like app.getElementById([Name of ListBox]) to access the selected item. The reason I am using this method is because my list of ListBox-es are dynamic.
I spent some time looking for this answer as well, but finally I tried one idea and it worked.
You can use e.parameter as an array so you can these two will give the same:
e.parameter.LIST_BOX_NAME
and
e.parameter['LIST_BOX_NAME']
So in the second sample any dynamic list box ID can be used. I use same handler for all added dropdown list and have this code to check what dropdown was changed and what value it has now:
if (e.parameter[e.parameter.source] == 'a'){
To change the content of the listBox you can use app.getElementById('ID of the listBox'), from there you can clear() and addItems again but you cannot read the listItems.
When I need to do this I usually store the list of items somewhere else, in a place that I can read anytime, for example the list of items can be stored as a string in the listBox tag itself so I have all items at hand to repopulate the listBox after I have clear it.

ComboBox Selected Item or ComboBox text Which you prefer to get the Combo Box Value in WinForm C#?

When i saw the Combo box Propriety Selected item and text Returns Same value in WinForms.
So What is Difference in between,.. Where i use ComboBox.SelectedItem ?
and Where i use ComboBox.Text?
combobox.text is always a string, combobox.selectedItem is an object
You can put any object to the ComboBox control.
SelectedItem will return this object.
Text will return string representation of the SelectedItem when ComboBoxStyle = DropDownList ( text portion is not editable), the result may be like this - SelectedItem.ToString().
Find more information here - ComboBox Class.
In your case, if you add strings into the ComboBox.Items, then there is no difference what to use SelectedItem or Text.