PickerView inside TableView implementation in Titanium - titanium-alloy

I have created a PickerView inside the TableView, that is on tableViewRow. But I'm not able to access the full properties of the Picker.
For example I'm not able to set the TextHint for the the PickerView
I'm not able to fetch the selectedRow in the picker in index.js
here is my code in index.xml
<Alloy>
<Window class="container">
<!-- <Label id="label" onClick="doClick">Hello, World</Label> -->
<TableView id="table">
<TableViewSection>
<TableViewRow>
<TextField id="id_membership_number" width="Ti.UI.FILL" hintText="Membership Number"/>
</TableViewRow>
<TableViewRow>
<Picker id="id_picker" selectionIndicator="true" onChange="picker_method" value="Sector" selectionIndicator="true">
<!-- On iOS, views can be added to picker rows -->
<PickerColumn id="column1">
<PickerRow title="Real Estate" id="id_picker_row">0</PickerRow>
<PickerRow title="Automobiles" id="id_picker_row">1</PickerRow>
<PickerRow title="Others" id="id_picker_row">2</PickerRow>
</PickerColumn>
</Picker>
</TableViewRow>
<TableViewRow title="Region"/>
<TableViewRow title="Membership Type"/>
</TableViewSection>
</TableView>
<Button id="id_member_search_btn" onClick="member_search_method"></Button>
</Window>
index.js
function picker_method(event){
event=$.id_picker;
Ti.API.info("User selected: " + event.getSelectedRow(0) + column.getSelectedRow(0));
}
On Console I get:
User selected: undefined

In your view:
<Alloy>
<Window class="container">
<!-- <Label id="label" onClick="doClick">Hello, World</Label> -->
<TableView id="table">
<TableViewSection>
<TableViewRow>
<TextField id="id_membership_number" width="Ti.UI.FILL" hintText="Membership Number"/>
</TableViewRow>
<TableViewRow>
<Picker id="id_picker" selectionIndicator="true" onChange="picker_method" value="Sector" selectionIndicator="true">
<!-- On iOS, views can be added to picker rows -->
<PickerColumn id="column1">
<PickerRow title="Real Estate"/>
<PickerRow title="Automobiles"/>
<PickerRow title="Others"/>
</PickerColumn>
</Picker>
</TableViewRow>
<TableViewRow title="Region"/>
<TableViewRow title="Membership Type"/>
</TableViewSection>
</TableView>
<Button id="id_member_search_btn" onClick="member_search_method"></Button>
</Window>
</Alloy>
In your JS:
function picker_method(event){
Ti.API.info("user selected : "+event.selectedValue);
}
You should read the change event documentation for more info about what is passed to the onchange handler http://docs.appcelerator.com/titanium/3.0/#!/api/Titanium.UI.Picker-event-change
Also, please note I removed the duplicate ID you had on the PickerRows, ID has to be unique.

Related

Devexpress Datagrid and Xamarin.Forms component in the same View

Can i have xamarin.forms component and Devexpress DataGrid in same View. I tried but only one shows.
Example:
<Entry Keyboard="Numeric" Placeholder="Enter Here" ></Entry>
<DatePicker FontSize="Large"></DatePicker>
<Button Text="Search"></Button>
<dxg:DataGridView ItemsSource="{Binding Path=Users}" RowHeight="90">
<dxg:DataGridView.Columns>
<dxg:TextColumn FieldName="Name" Caption="Name" IsReadOnly="true">
<dxg:TextColumn.Width>
<OnIdiom x:TypeArguments="GridLength" Tablet="200" Phone="120" />
</dxg:TextColumn.Width>
</dxg:TextColumn>
</dxg:DataGridView.Columns>
</dxg:DataGridView>
</Stack>```

is it possible to change css properties of class label in nativescript

I have used label class for every label in my project. If any other font color like
class="label font-clr-green"
is applied then it not taking green color. So I decided to overwrite the label class in app.css but it's also a failure. I need to know whether label class can be overridden or not.
I checked your Playground Sample and what I could deduce from it is, that the <Label> used in the problem part is not taking the green color as it should be. Well, that's because you are using this <Label> element inside a <StackLayout> having class input-field. It seems like, CSS for .input-field Label is pre-defined.
The solution to your problem, would be to rename this class input-field to something else. That's all it needed. Below is the updated XML part. You can also check my attached Playground demo with the fix.
<Page loaded="pageLoaded" class="page" xmlns="http://www.nativescript.org/tns.xsd">
<ActionBar title="Home" class="action-bar">
</ActionBar>
<ScrollView>
<StackLayout class="form">
<!--this was working fine -->
<Label textWrap="true" text="Play with NativeScript!" class="label font-weight-bold m-b-5 fcg" />
<Label textWrap="true" text="Play with NativeScript!" class="label font-weight-bold m-b-5"
color="green" />
<!-- the problem was here, solution was to rename input-field to input-field-1 -->
<StackLayout class="input-field-1">
<StackLayout class="okay">
<Label text="Active Flag" class="label font-weight-bold m-b-5 fcg" />
</StackLayout>
<Switch checked="true" class="switch fcg"
horizontalAlignment='left' margin="0" />
<StackLayout class="hr-light"></StackLayout>
</StackLayout>
</StackLayout>
</ScrollView>
Working Playground Demo.

Event Pass element source with short syntax

This Method worked button event passed TreeView element to ViewModel but short syntax event not passed, Where is the problem? Thanks.
<Button Content="Search in TreeView" Height="34" Width="100">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<cal:ActionMessage MethodName="SearchTreeView">
<cal:Parameter Value="{Binding ElementName=TreeView}" />
</cal:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
</Button>
<TreeView x:Name="TreeView" ItemsSource="{Binding TreeViewSource}"/>
Short syntax event
<Button x:Name="SearchTreeView" Content="Search in TreeView" cal:Message.Attach="[Event Click] = [Action SearchTreeView($source.TreeView)]" />
<TreeView x:Name="TreeView" ItemsSource="{Binding TreeViewSource}"/>
You don't need to specify $source.Treeview, just the name of the element, TreeView is enough
<Button x:Name="SearchTreeView" Content="Search in TreeView" cal:Message.Attach="[Event Click] = [Action SearchTreeView(TreeView)]" />
<TreeView x:Name="TreeView" ItemsSource="{Binding TreeViewSource}"/>
That said, it's NOT a good idea to pass a control to the ViewModel. If you want to do something with the the selected item, you should bind TreeView's SelectedItem property to a property on your ViewModel and access this from your SearchTreeView method, eg
<Button x:Name="SearchTreeView" Content="Search in TreeView" cal:Message.Attach="[Event Click] = [Action SearchTreeView()]" />
<TreeView x:Name="TreeView" ItemsSource="{Binding TreeViewSource}" SelectedItem={Binding MySelectedItem}"/>

How to use if="some condition" in ZK template tag

I have a <template> tag in my ZUL file, and I want to use this template when some condition accured (for example, when some LABEL's value change to some text).
Please look at below code... As you can see, "templateStatus" is my label's name, but it did not work.
How can I fix this issue?
<template name="allTaskTemplate" var="allTask" if="templateStatus.value == 'allTask'">
<row>
<label value="" />
<label value="#load(allTask.documentDTO.docTypeDTO.title)"/>
<label value="#load(allTask.documentDTO.docNumber)"/>
<label value="#load(allTask.documentDTO.docDateTime)"/>
<label value="#load(allTask.assignerID)"/>
<label value="#load(allTask.assigneeID)"/>
<label value="#load(allTask.assignDateTime)"/>
<label value="#load(allTask.assignDateTime)"/>
<label value="#load(allTask.assignDateTime)"/>
<label value="#load(allTask.assignDateTime)"/>
<label value="#load(allTask.documentDTO.docTypeStateDTO.stateActionDTO.actionDTO.title)"/>
<label value="#load(allTask.catalogDTO.catalogTypeDTO.title)"/>
</row>
</template>
</grid>
Using an if statement:
<zk if="${vm.type=='foo'}">
<!-- Child components -->
</zk>
<zk if="${vm.type=='check'}">
<!-- Child components -->
</zk>
<zk if="${vm.type=='something'}">
<!-- Child components -->
</zk>
<zk if="${vm.type=='value'}">
<!-- Child components -->
</zk>
See the below example of ZK. You can use conditional templates...
<grid model="#bind(vm.itemList) #template(vm.type eq 'foo'?'template1':'template2')">
<template name="template1">
<!-- child components -->
</template>
<template name="template2">
<!-- child components -->
</template>
</grid>
For more information, you can see the official page of ZK, Collection and Selection.
Se the below code for...
<menubar id="mbar" children="#bind(vm.menuList) #template(empty each.children?'menuitem':'menu')">
<template name="menu" var="menu">
<menu label="#bind(menu.name)">
<menupopup children="#bind(menu.children) #template(empty each.children?'menuitem':'menu')"/>
</menu>
</template>
<template name="menuitem" var="item">
<menuitem label="#bind(item.name)" onClick="#command('menuClicked',node=item)" />
</template>
</menubar>
See the above. Using more than two templates you can do something like this. I don't know your requirement, but you can use the above logic and implement it in your code.
Or you can see the ZK Forum for the same, Zk forum.

How do i bind data to a child View Model?

I have a page with two different View Models:
<?page title="My page" contentType="text/html;charset=UTF-8"?>
<div apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('com.mycompany.FirstViewModel')">
<!-- A lot of unimportant stuff -->
<tabbox>
<tabs>
<tab label="Tab1" ></tab>
<!-- Other unimportant tabs -->
</tabs>
<tabpanels>
<tabpanel>
<include src="inc/other.zul" p="#ref(vm.selected)" pid="#ref(vm.selected.id)" ></include>
</tabpanel>
</tabpanels>
</tabbox>
</div>
And the include is:
<window>
<label id="sid" value="#load(pid)" />
<div apply="org.zkoss.bind.BindComposer"
viewModel="#id('vms') #init('com.mycompany.SecondViewModel')">
<listbox model="#id('vars') #load(p.someList)"
selectedItem="#bind(vms.selected)"
emptyMessage="No data in list">
<!-- Template and stuff -->
</listbox>
<label id="sid1" value="#load(pid)" />
</div>
</window>
The problem is that once I define the second viewModel, all the external references are inaccessible: I have a value for the first label, but I have no values for the listbox or the second label. Is there a way to do that? I tried with no success to do this:
<div apply="org.zkoss.bind.BindComposer"
viewModel="#id('vms') #init('com.mycompany.SecondViewModel')" list="#ref(p.someList)">
<listbox model="#id('vars') #load(list)"
selectedItem="#bind(vms.selected)"
emptyMessage="No data in list">
I could merge the second View Model in the first one, but that wouldn't be very convenient! I am also open to other solutions which allow me to have a modular approach.
My version of ZK is 6.0.1
The reason you are unable to access the external components is your composer i.e BindComposer you have same composer for the Main zul as well as for the Included zul. You need to access the Included Listbox from external ZUL.
So remove the Composer of Include ZUL, give an ID to window you have two Space Owners access the inner Listbox
<?page title="My page" contentType="text/html;charset=UTF-8"?>
<div apply="org.zkoss.bind.BindComposer"
viewModel="#id('vm') #init('com.mycompany.FirstViewModel')">
<!-- A lot of unimportant stuff -->
<tabbox>
<tabs>
<tab label="Tab1" ></tab>
<!-- Other unimportant tabs -->
</tabs>
<tabpanels>
<tabpanel>
<include id="include" src="inc/other.zul" p="#ref(vm.selected)" pid="#ref(vm.selected.id)" ></include>
</tabpanel>
</tabpanels>
</tabbox>
</div>
<window id="win">
<label id="sid" value="#load(pid)" />
<div
viewModel="#id('vms') #init('com.mycompany.SecondViewModel')">
<listbox id="listbox2" model="#id('vars') #load(p.someList)"
selectedItem="#bind(vms.selected)"
emptyMessage="No data in list">
<!-- Template and stuff -->
</listbox>
<label id="sid1" value="#load(pid)" />
</div>
</window>
Now while accessing in your BindComposer declare variable as public :
Listbox include$win$listbox2;
in your doAfterCompose() add this line
Sysout("You can access your inner Listbox and it is:"+include$win$listbox2);
Now you see you will not get your Listbox NULL!!
Link : http://books.zkoss.org/wiki/ZK_Developer's_Reference/UI_Composing/ID_Space
It is (was) actually a bug in ZK, which has been fixed for a future version.

Resources