how to set datagrid numberbox prefix onchange combobox - datagrid

I am using datagrid with inline editor which have validatebox, numberbox, and combobox. What I am try to do is when I select the combobox, I need to set numberbox prefix as currency symbol as I want. If I want to set the value to the numberbox, usually write like this:
var ed8 = $("#dg").datagrid("getEditor", {index:idx, field:'cost'});
$(ed8.target).numberbox('setValue',value);
but I am stack on case how to change/set the property "prefix" of numberbox.
One more thing that I want to ask, Is that possible to set multiple prefix in one field (one row one prefix) of datagrid?

I just found the solution by put the code like this.
var ed8 = $("#dg").datagrid("getEditor", {index:idx, field:'cost'});
var opts = $(ed8.target).numberbox('options');
opts.prefix = '$';
It is possible to set multiple prefix on a field
hope this can help others.

Related

Appmaker Input Form, change options based on earlier dropdown choices

Hypothetical:
Say i'm having someone order a cake and they choose vanilla or chocolate, and then they have to choose a frosting
if vanilla: strawberry or buttercream
if chocolate: mocha, dark chocolate or buttercream.
Right now the frosting value in the data model can accept all four options, so all four show up in the dropdown.
a) is there a way to change the binding for the second dropdown after the first is chosen?
This can be done without having the data saved in any datasource. Simply do the following...
Suppose the first dropdown is named primaryDropdown and the second dropdown is called secondaryDropdown. In the primaryDropdown options set the following:
["Vanilla", "Chocolate"]
Also, make sure to uncheck the option allowNull and on the onAttach event handler, place the following:
widget.value = "Vanilla";
Now we move on to the secondaryDropdown. Here, we will do a binding so place the following in the options value:
getAvailableOpts(#widget.root.descendants.primaryDropdown.value)
In the client script, we need to make sure that function exists so please paste the following in any client script:
function getAvailableOpts(primaryValue){
var options;
switch(primaryValue){
case "Vanilla":
options =["Strawberry","Buttercream"];
break;
case "Chocolate":
options = ["Mocha","Dark Chocolate","Buttercream"];
break;
default:
options = [];
}
return options;
}
From here, you are good; However we can still make it better. For that, make sure to also uncheck the allowNull option for the secondaryDropdown and then we need to add some logic in the onValueChange event handler of the primaryDropdown.
widget.root.descendants.secondaryDropdown.value = widget.root.descendants.secondaryDropdown.options[0];
References:
https://developers.google.com/appmaker/ui/input-widgets#dropdown
https://developers.google.com/appmaker/ui/binding#bindings
https://developers.google.com/appmaker/scripting/client#use_scripts_in_binding_expressions
Im guessing you set the dropdown "possible value" options in the data source and you have those fields as just string fields in your table.
the quick and dirty way to do this is go to the Cake drop down and on the Property Editor>Events>OnValueChange select Custom Action and use this Code
if(widget.value==="Vanilla"){
widget.root.descendants.Field.options = ['Strawberry','Buttercream'];
}else if (widget.value === "Chocolate"){
widget.root.descendants.Field.options = ['Mocha','Dark Chocolate','Buttercream'];
}
"Field" here is replaced with the name of the dropdown box for your frostings
also go to the property editor of the frostings dropdown and delete everything in the options field there.
I was trying to solve for a similar situation and created an additional table to serve as a lookup.
I have a drop down for CATEGORY with possible options set on the field in the main data source.
Then I have a second table with 2 Columns: CATEGORY, and SUB_CATEGORY.
On the entry form I have options for the SUB_CATEGORY drop down set to SUB_CATEGORY on the CATEGORY_MATRIX lookup table.
Then for an onValueEdit event on the CATEOGRY drop down I have a script to reload the CATEGORY_MATRIX table source based on the value of the CATEGORY drop down in the query so when the CATEGORY is selected only valid SUB_CATEGORY options are shown in the second drop down.
var datasource = app.datasources.CATEGORY_MATRIX
datasource.query.filters.CATEGORY._equals = newValue;
datasource.load();
There may be more efficient ways to do this but the benefit is I could create another form page and dynamically add new combos so there isn't any required code change as new combos are needed.

Add grid columns dynamically

I created a form with a single data source: InventJournalTable.
I also added a grid on it and two field from the data source : JournalType and JournalId
The ActionPane has a button and in its clicked event handler I am trying to do the following:
1. add a new data source and join it with the current one on JournalId
2. add to fields from the newly added data source to the current Grid.
This is what I have until now ... just for testing.. I have tried to access data source and add a range. It works nice, maybe the join is working too, but how can I add those two fields?
void clicked()
{
Query query;
QueryBuildDataSource qbdsInventJournalTable;
QueryBuildDataSource qbdsvwInventJournals;
super();
query = InventJournalTable_ds.query();
qbdsInventJournalTable = query.dataSourceTable(tableNum(InventJournalTable));
qbdsInventJournalTable.addRange(fieldNum(InventJournalTable, JournalType)).value(queryValue(InventJournalType::LossProfit));
qbdsvwInventJournals = qbdsInventJournalTable.addDataSource(tableNum(vwInventAdjJrnlCostAmount));
qbdsvwInventJournals.addLink(fieldNum(InventJournalTable, JournalId), fieldNum(vwInventAdjJrnlCostAmount, JournalId));
qbdsvwInventJournals.joinMode(JoinMode::OuterJoin);
//gridOverview.addDataField(
InventJournalTable_ds.executeQuery();
}
One more thing, I plan to add another button named "Remove details" which will remove the second data source and the grid should return to its initial state.
Am I on the right track at least? Can I get some hints about this?
Instead of dynamically adding the datasource/fields/etc have you considered just adding them on the form, but disabling the joined datasource until you need it? Seems to me like a simpler/cleaner solution.
See here:
http://olondono.blogspot.com/2008/06/how-to-enable-or-disable-joined.html

Flex: how to select each element/instance of a repeater

I'll explain my problem as brief as possible. I have a variable bandName, the value is String that i get through an API.
public function haalNaam(selectedChart:Object):String
{
var bandName:String = selectedChart.name;
}
I use this var in a repeater for a label. This repeater repeats 5 times, so it shows the 5 most hyped artists:
<repeater>
<label text="{haalNaam(lastfmCollection.currentItem)}"/>
</repeater>
Next, i had to transport the var bandName to another component. I managed to do this with this command:
var theName = "LastFmApi(this.parentApplication).bandName".
This code works, but I only manage to get the bandName of the last element in the repeater (5th one). I have no idea how i can
receive the names of the artists 1,2,3 or 4. How can i get to those values?
First, it doesn't look like what you've pasted in is functional code (your haalName function doesn't return anything, and your repeater doesn't have the id referred to in the label).
Second, why don't you just use lastfmCollection.currentItem.name in the label's text property, and skip the function call?
Third, you don't say exactly what the goal is, so I'll assume that you want to click one of the items in the repeater and put the label text in the variable theName. That would look like this:
theName=(event.target as Label).text;
Note that you may also want to consider using a DataGroup.

Converting a string into a CheckBox

I have a string which is ultimately the id of a CheckBox.
What I need to be able to do is to access the CheckBox's properties from the string
var myCheckBox:Object;
var myString:String;
myString = "checkbox_1"
myCheckBox = Object(myString); ?!?!
... and then I'd need to get to myCheckBox.selected, and myCheckBox.label etc
easier answer:
if(this.hasOwnProperty(myString) && this[myString] is CheckBox) {
myCheckBox = this[myString] as CheckBox
}
It's a bit of overcoding (since the as keyword will return a null if it's not a checkbox and you could better handle it that way with potentially less code), but that should do ya.
Best of luck.
If you know what DisplayObjectContainer (e.g. Sprite, MovieClip) the CheckBox is inside you can use getChildByName.
Unfortunately if you are using Flex containers (like Group) there is no function getElementByName(). There is getElementAt so you could write a loop that iterates over all of a Groups elements until it encounters one that matches the name you have.

dynamically generate ComboBox name

I have a script that parses some complex XML. When the XML element is of a certain type, it generates a comboBox using the XML element's children to populate the box. I then want to check all of the values of the all the generated ComboBoxes against their correct answers (which is also info stored in the XML file). When creating the ComboBoxes, I added an "id" property. However, it seems that I cannot them use:
dynamicQuestion.id.selectedItem.labelField
to check the answers. However, I am able to get the labelField if I know the variable name used to create the ComboBox.
dynamicQuestion.selectedItem.labelField
This indicates (to me) that I need to dynamically generate the variable name as I'm creating new instances of the ComboBox. But how do I dynamically generate a variable name? If I use
var thisBox:String = "box"+boxCount;
var newBox:ComboBox = thisBox as ComboBox;
I get an implicit coercion error. I also tried changing the creation statement to a function that accepted an argument, "thisBox," but this didn't work either. Conceptually, this seems quite simple, but I'm having a hard time putting it to practice. It seems that the comboBox's id is what is generated by created the box using script (e.g., var thisBox). How do I dynamically generate this name?
Use an array as Stefan suggested. If you must use string identifiers, you can create an object and use it as an associative array.
var combos:Object = {};
var boxCount:Number = 1;
var thisBox:String = "box"+boxCount;
//you can store comboboxes in the object using the following syntax
combos[thisBox] = new ComboBox();
//or
combos.box2 = new ComboBox();
//or
combos["box3"] = new ComboBox();
trace(combos.box1.selectedItem.labelField);
trace(combos.box2.selectedItem.labelField);
trace(combos.box3.selectedItem.labelField);
Why don't you store all your dynamically created combo boxes in an array? When you want to evaluate them you iterate over the array and access selectedItem.labelField.

Resources