target and display an object of list control in flex - apache-flex

i have made a list control. i want to display the name of the objects in it in a text control box
the code i am using here is
public function add(event:MouseEvent):void
{
var str:String;
str = mylistcontrol.dataProvider.getItemAt(0).toString();
mytextarea.text += str+ "has been added";
mytextarea.text += "\n";
}
The problem with this code is i am using index value of 0. however i want to display the name of object on which i have clicked or which is highlighted.
any ideas and thoughts?

When you say the name of the object do you mean the name of the ItemRenderer?
If that's the case one method you could use involves creating a custom event and a custom item renderer...
Create a custom ItemRenderer when clicked dispatch your CustomEvent which would a have a data property into which you can put anything you like.

Related

Is it possible to create an input widget in app maker? Or how to make a multiselect with numbers?

I want to have an input widget that is similar to the built-in multiselect input widget but where instead of checks a number is given, say for example in the pizza order app example, one would be able to pick 3 for the first topping, 0 for the second topping and 1 for the third topping.
Since input widgets are not modifiable and display widgets do not have the "value" field, I thought I could do it through the "submit" button event, but that uses widget.datasource.createItem() which is quite opaque and I don't know how I would get the data from the display widget and integrate it to create an item.
Based on your requirement, I created a simple implementation using a list widget and a client-side calculated model. I also used a multi-select widget to show the dynamic mapping of selections to the actual input widget.
Editor View
From a selected list of toppings, the calculated model will be populated and render the sublist of toppings together with an input field for the user to enter the number of desired toppings.
The multi-select widget is bound to a parameter in the datasource.
Here is the query function to populate the list onValueChange.
function generateTopingList(query,recordFactory,callback) {
var toppingList = [];
if(query.parameters.topingList){
query.parameters.topingList.forEach(function(e,i){
var newRecord = recordFactory.create();
newRecord.Name = e;
newRecord.Amount = 0;
toppingList.push(newRecord);
});
}
callback.success(toppingList);
}
The list widget will make use of this datasource and bind the name and amount field into a label and a text input.
Preview
I have a button to emulate a SAVE action To capture the entered values and display it in another label.
function showResults(selectedItems,resultWidget){
resultWidget.value = " \n";
selectedItems.forEach(function(e,i){
var toppingName = e.Name;
var enteredAmount = e.Amount;
//for display only
resultWidget.value += toppingName + " - " + enteredAmount + "\n";
});
}
See this simple video on how this works in action.
With regards to creating your own input widgets, app Maker gives you an option to create re-usable sections in your app through the concept of "Page Fragments". You can implement the logic separately, like in my case it's the list widget, then wrap it into a page fragment. You can then use this fragment in your pages.

Is it possible to load AppMaker DropDowns with an Option Text and and Value?

I've been able to set the options on an AppMaker DropDown by doing this sort of thing:
google.script.run
.withSuccessHandler(function(oA){app.pages.Notes.descendants.Dropdown1.options=oA;})
.getSelectOptions();//oA is just an array
But I'd like to know how to do load different values in the options and value like we can do it in javascript with something like this:
function updateSelect(vA){
var select = document.getElementById("sel1");
select.options.length = 0;
for(var i=0;i<vA.length;i++)
{
select.options[i] = new Option(vA[i].option,vA[i].value);
}
}
And I tried this by trying to get a hold of the dom element as follows:
var elem=app.pages.myPage.descendants.myDropDown.getElement();
elem.options.length=0;//always gives me an error because options doesn't seem to exist in that object.
So for now I've been using the standard HTML dom elements in an AppMaker Html widget and that works okay as long as your select is on the first page. If it's not on the first page I have found that the onChange event can't load Widgets on pages that are not visible. It is interesting to note however that you can change the contents of HTML widgets even if they are on other non visible pages.
Anyway the simple question is how can one load one thing into value and another thing into option text in an AppMaker DropDown Widget?
<option value="value">text</option>
If you have a predefined array for your options and values you could do the following for your onAttach Event of your dropdown:
var options = ['one thing','two thing','three thing'];
var names = ['another one thing','another two thing','another three thing'];
widget.options = options;
widget.names = names;
In this case the values that would get recorded would be the options array, but the items that would be displayed would be from the names array. Hope this gets you on the right path.

Is it possible to pass a radiobuttonList to a method in a custom class as a parameter in asp.net

I have a few different pages with a radiobutton list that I populate using a collection of answers in the page load event of each page. I was wondering rather than repeating the same code on 4 different pages, is it possible to pass in the radio button list as a parameter to my own class that I made and populate it in there? I can't seem to see A ListItem parameter to pass in.
My code is
foreach (var item in collection)
{
RadioButtonList.Items.Add(item);
}
Instead of having to repeat that, I'm trying to pass the list and the collection to my Person Class, and create a method in there that does the same.Any help is appreciated!
Unless I'm missing something obvious, can you not have something like a static function that has the RadioButtonList and collection as parameters?
public static void PopulateMyRadios(RadioButtonList rdoButtons, MyCollection collection)
{
foreach (var item in collection)
{
rdoButtons.Items.Add(item);
}
}
Yes.. We can create a method of parameter string array which are hold the text of radio button required. Then create html radio button list by using string array and input this radio button list to any of div of corresponding page as inner HTML.

How to retrieve the pre edited value of the cell of a datagrid to an itemeditor in a flex

I wrote a custom item editor for a datagrid in flex. My question is how to retrieve the pre-edited value of the datagrid cell after the item editor initializes and also in the custom item editors code.
I don't think it is possible to get the old value once you are in the item editor. I would do this manually by listening to the "itemEditBeginning" event and keeping a variable with the value of the cell. You can then reference that value through the "parent", "parentDocument" or "outerDocument" properties in the item editor, depending on whether you are using an inline item editor or a separate class.
In the "itemEditEnd" event you can access the old value as:
var oldValue:String = event.currentTarget.dataProvider[event.rowIndex].VALUE_FIELD;
and the new value as:
var txtControl:mx.controls.TextInput = event.currentTarget.itemEditorInstance as mx.controls.TextInput;
var newValue:String = txtControl.text;
If you are using a custom itemRenderer you need to change "mx.controls.TextInput" for your custom itemRenderer.

Flex ComboBox, default value and dataproviders

I have a Flex ComboBox that gets populated by a dataprovider all is well...
I would now like to add a default " -- select a item --" option at the 0 index, how can I do this and still use a dataprovider? I have not seen any examples of such, but I can't imagine this being hard...
If you don't need the default item to be selectable you can use the prompt property of ComboBox and set the selectedIndex to -1. That will show the string you set propmt to as the selected value until the user chooses another. It will not appear in the list of options, however.
I came across this problem today and wanted to share my solution.
I have a ComboBox that has an ArrayCollection containing Objects as it's dataprovider. When the application runs, it uses a RemoteObject to go out and get the ArrayCollection/Objects. In my event handler for that call I just have it append another object to the beginning of the ArrayCollection and select it:
var defaultOption:Object = {MyLabelField: "Select One"};
myDataProvider.addItemAt(defaultOption, 0);
myComboBox.selectedIndex = 0;
This is what my ComboBox looks like for reference:
<mx:ComboBox id="myComboBox" dataProvider="{myDataProvider}" labelField="MyLabelField" />
The way I've dealt with this in the past is to create a new collection to serve as the data provider for the combobox, and then I listen for changes to the original source (using an mx.BindingUtils.ChangeWatcher). When I get such a notification, I recreate my custom data provider.
I wish I knew a better way to approach this; I'll monitor this question just in case.
This can be used following code for selected default value of combobox
var index:String = "foo";
for(var objIndex:int = 0; objIndex < comboBox.dataProvider.length; objIndex++) {
if(comboBox.dataProvider[objIndex].label == index)
{
comboBox.selectedIndex = objIndex;
break;
}
}
<mx:ComboBox id="comboBox" dataProvider="{_pageIndexArray}" />

Resources