Appcelerator. Update row labels - appcelerator-mobile

Titanium SDK version: 1.7.0
iPhone SDK version: 4.2
I am developing an iOS app using Appcelerator.
In this app I got a window that contains a table of contact data.
The user can click an item in this table and a new window opens up where they can
edit the contact details and then click save.
After the user clicked save I want the table in the parent window to update its data for the clicked row with the info sent back from the edit window.
My question is. How can I update the labels in a specific row if I got the row index?
I am planning to make this update from a custom event so I will not be using e.index only the "saved" index number for example 5.
I know there is a function called "updateRow" but I seem to only be able to update title of the row not its child elements.
Thankful for all input!

Here is the approach I would take.
Assumptions
win1 contains the table (table1) and
an array that contains rows that you
can update (data)
win2 is where the
editing occurs
On the 'save' button click in win2, fire an event with the updated contact details before you close the window;
Ti.App.fireEvent('contact.change' , updatedContactObject );
// Do database save here if required
win2.close();
Add an eventListener in win1:
Ti.App.addEventListener( 'contact.change' , function(e){
var updatedContactObject = e.updatedContactObject;
//
// update the array and the row here
//
data[ updatedContactObject.id ] = updatedRowData;
table1.setData(data);
});

In my experience it is best to tableView.setData(rowArray) whenever you make a change, rather than selectRow, updateRow, etc. Regarding the actual row elements, you should be able to navigate by using row.children[x].children[x]. The problem is that you will have to pay close attention to the hierarchy. Let us know if you find a better way!

Related

Calling page in a new tab when an item's value changes

I am using apex 21.1.
I have built a report with a form. The report page(2) has another region "Param" which has item P2_DEPTNO. The form(Modal Page -3) is for creating new records and editing existing records. There is a CLOSE DIALOG process in page 3 and it has P3_DEPTNO as a value for "Items to Return" attribute. Page 2 has a DIALOG CLOSED dynamic action with a true action of SET VALUE that sets P2_DEPTNO with the value of P3_DEPTNO. This is when I should call page 4 in a new tab(when P2_DEPTNO is assigned P3_DEPTNO's value.I am calling page 4 using the code...
apex.navigation.openInNewWindow('f?p=&APP_ID.:4:&APP_SESSION.:::4');
Unfortunately, it does not work and I do not know why. However, if the dynamic action is of type Alert, it works fine and displays the alert when P2_DEPTNO's value changes. What could be the reason for that?
ws=ESLAM_WS
un= forhelp
pwd=Forhelppwd$
app= Call new window
pages= 2,3 and 4
P.S: It works if I change P2_DEPTNO's value manually. But I need it to work when the SET VALUE dynamic action set it's value.
I tried to log in into you app, added another dynamic action event "Execute Javascript code" and entered your code without ':::4' part and it worked well for me.
so:
apex.navigation.openInNewWindow('f?p=&APP_ID.:4:&APP_SESSION.');
(also I have left an alert there that you mentioned worked anyway). If someone else fixed it meantime, I hope she/he will document here what she/he did.

Finding a wxMenu's Selected Radio Item

Let's say that I have a group of radio items in a wxMenu. I know that exactly one of these will be checked at any given time.
Does the wxMenu or some other construct hold onto the index of the checked item, or do I need to call the isChecked on each radio item till I find the checked element to find it's index?
I've asked this question about how to do that, but I'd much prefer wxWidgets saved me from doing that everywhere.
No, saving the index of the last selected item (as shown in ravenspoint's answer) or using wxMenuBarBase::IsChecked() until you find the selected radio button is the only way to do it.
For wxWidgets to provide access to the currently selected button it would need not only to store it (which means not forgetting to update not only when the selected changes, but also when items are inserted into/deleted from the menu, so it's already not completely trivial), but to somehow provide access to the radio items group you're interested in, which would require being able to identify it and currently there is no way to do it and adding it isn't going to be particularly simple.
What could be done easily, however, is writing a reusable function int GetIndexOfSelectedRadioItem(int firstItem) that would start at the given item and call IsChecked() on subsequent items until it returns true and return the offset of the item. You should be able to do it in your own code, but if you'd like to include such function in wxWidgets itself (as a static wxMenuBar method, probably), please don't hesitate to send patches/pull requests doing it!
It is easy enough to roll your own.
Bind an event handler to wxEVT_COMMAND_RADIOBUTTON_SELECTED for every button. In the handler, extract the ID of the selected radio button and store it somewhere.
Like this:
ResolMenu = new wxMenu();
ResolMenu->AppendRadioItem(idRcvLoRez,"Low Resolution");
ResolMenu->AppendRadioItem(idRcvMeRez,"Medium Resolution");
ResolMenu->AppendRadioItem(idRcvHiRez,"High Resolution");
ResolMenu->Check( idRcvLoRez, true );
Bind(wxEVT_MENU,&cFrame::onRcvRez,this,idRcvLoRez);
Bind(wxEVT_MENU,&cFrame::onRcvRez,this,idRcvMeRez);
Bind(wxEVT_MENU,&cFrame::onRcvRez,this,idRcvHiRez);
void onRcvRez( wxCommandEvent& event )
{
myRezID = event.GetId();

Execute query on active region

I have one page where i have about 8 tab region. Each region has a select statment. They are executed when accessing the page (page load) at the same time. Because i have 8 select statment that executes at same time it leads to pure performance.
My question is how to execute the query only on active region.
You can try this one
Create Dynamic Action on event "Page Load"
Create true action "Execute javaScript Code":
window.setTimeout(function(){
$('.a-Region-carouselLink').click(function(){
apex.event.trigger(document, 'tabChanged', this);
})
}, 500);
Set "Fire On Page Load" to "Yes"
Create Custom event "tabChanged"
Create true action in DA custom event "Execute JavaScript Code":
console.log(this.data);
Test it - each time you click the tab, DA prints to console currently clicked anchor.
Of course it is not perfect because of the 0.5s delay. Still it allows you to listen what tab was "clicked".
To make your scenario work I would do:
create page item PX_TAB
create true action in custom event to set value of PX_TAB
create true actions in custom event to refresh reports within tabs
set "Page Items to Submit" to "PX_TAB" in each report to be refreshed
add condition to each report comparing value of item PX_TAB - it will execute SQL query only when PX_TAB has expected value
edit 2016.08.13
You can bind tabs by simple adding listener to the tabs
$(document).on('mousedown', 'a.t-Tabs-link', function(){
//this is an anchor used as tab
console.log(this)
})
If you want to keep it in APEX way enter code from below in Execute when Page Loads page section or create new dynamic action On page load
$(document).on('mousedown', 'a.t-Tabs-link', function(){
apex.event.trigger(document,'tabChanged', this);
})
and then add dynamic action bound to Custom event named tabChanged. Whenever tab is clicked the tabChanged event is triggered, and in Execute JavaScript Code you can reference current tab by this.data
Try to create buttons and set behavior of each button to display required region and hide others (create hidden item, then create buttons that set values 1,2,3 etc., then add conditions to every region to display region 1 only when hidden item equal 1, region 2 for item value 2 etc.

How to create a Checkbox Change event for a wxGrid cell

I've created a wxGrid, populated it with data, and have created a column that contains checkboxes, and made them editable. All good so far.
co_Grid->SetReadOnly(at_RowCount, 24, false);
co_Grid->SetCellRenderer(at_RowCount, 24, new wxGridCellBoolRenderer);
co_Grid->SetCellEditor(at_RowCount, 24, new wxGridCellBoolEditor);
What I want to be able to do now is to add an event handler for the checkbox toggle event.
I've tried using the OnCellValueChanged event for the grid, but that only fires after the user leaves the cell, because before then the editor is still open (and the cell hasn't actually changed yet)
I'm pretty sure that I need to create an event handler for the wxGridCellBoolEditor but that's where I'm struggling.
I tried connecting an event in the OnEditorShown event, but that didn't go well (unhandled exception when I click on the cell to open the editor):
void cTeamGrid::OnEditorShown( wxGridEvent& ev )
{
int row = ev.GetRow(),
col = ev.GetCol();
co_Grid->GetCellEditor(row, col)->GetControl()->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED,
wxCommandEventHandler(cTeamGrid::OnGridCheckChange), NULL, this);
}
What am I doing wrong?
I had a similar problem myself. I bypassed it by setting the checkbox column to read-only and having the wxGrid control manually handle the click event to toggle the checkbox state (you also have to manage the double-click). This method is not the most orthodox, also because now each click on the cell, and not on the checkbox, will change the state. In my opinion, however, this can also be a desirable behaviour. In addition, this enables you to let the user change the checkbox with the keyboard (by capturing the KeyPress events).

Appcelerator. Buttons in rows are unclickable

Titanium SDK version: 1.6.2 (tried with 1.7 too)
iPhone SDK version: 4.2
I am developing an iPhone app and I am fetching data from my API and presenting it in a table. In this table I got a button on each row that should allow the user to add that person to his or her contacts. The only problem with the code (I think) is that only the last button responds when being clicked. Nothing happens when I click the other buttons.
This is my code: http://pastie.org/1932098
What is wrong?
You are adding the button.addEventListener outside of the for statement, and since you are overwriting the button var with each iteration, the eventListener only attaches to the last button created.
This probably isn't the best way to work this, but to fix your problem, move the button.addEventListener inside the for statement, and then check for a unique identifier in the object that gets sent to the event. Example:
for (x=0;x<5;x++) {
var button = Titanium.UI.createButton({
height:40,
width:100,
top:50*x,
id:x
});
var label = Titanium.UI.createLabel({
text:'LABEL '+x
});
button.add(label);
win1.add(button);
button.addEventListener('click', function(e){
Ti.API.info('Button clicked '+e.source.id);
});
}
The button.id property is just made up, but now you can see which button sends the event. You could also use title, or anything else that is unique.
Other options to look at are creating unique variable names for each button, but that's probably more work. Also, instead of working with putting a button in the table row, use a label or image, then listen for the event generated by the table or row.