I have a ListView that's hooked to a dataCollection, is it possible to add editActions?
Can't seem to find a way to add these to my ItemTemplate or ListItem.
Here's my (shortened) view:
<ListView id="listViewSpots" defaultItemTemplate="history">
<Templates>
<ItemTemplate name="history" id="itemTemplateHistory" canEdit="true">
<Label bindId="serie" class="serie" />
</ItemTemplate>
</Templates>
<ListSection id="listSectionSpots" dataCollection="spot" dataFilter="listFilter">
<ListItem itemId="{id}" serie:text="{serie}" searchableText="{serie}" />
</ListSection>
</ListView>
You can add custom actions like this:
"ListItem[platform=ios]":{
accessoryType: Titanium.UI.LIST_ACCESSORY_TYPE_DISCLOSURE,
editActions: [{ title: "Add",
style: Ti.UI.iOS.ROW_ACTION_STYLE_DEFAULT },
{ title: "Archive",
style: Ti.UI.iOS.ROW_ACTION_STYLE_DEFAULT },]
}
Editable and EditActions are just regular properties of a ListItem and can be added as such. Through a transform function (dataTransform) you can make this customizable as well
<ListView id="listViewSpots" defaultItemTemplate="history">
<Templates>
<ItemTemplate name="history" id="itemTemplateHistory" canEdit="true">
<Label bindId="serie" class="serie" />
</ItemTemplate>
</Templates>
<ListSection id="listSectionSpots" dataCollection="spot" dataFilter="listFilter">
<ListItem
itemId="{id}"
serie:text="{serie}"
searchableText="{serie}"
editable="{editable}"
editActions="{editActions}"
/>
</ListSection>
</ListView>
This way you can still configure it per ListItem
Yes it is possible.
Can you specify your issue ?
Can you enable slide action?
Do you wanna know how to handle click event?
Maybe this can help you:
"ItemTemplate[platform=ios]":{
canEdit: true
}
Related
I am learning to make an app in NativeScript (Angular 2). In my item page, I want to have a button so that when I press it, I can change Label into TextView/TextField for editing the information of the item.
I know that I can use editable in TextView but I still want to know if it is feasible to have the button with that functionality. Thank you !!
item.component.html:
<StackLayout>
<Label class="h3" text="Name: {{ item.get_name() }}" textWrap="true">
</Label>
<Label class="h3" text="Credit: {{ item.get_credit() }}"></Label>
<Button class="btn" text="Edit" (tap)="change()"></Button>
</StackLayout>
<!-- After pressing the button -->
<StackLayout>
<TextView class="h3" [text]="item.get_name()" textWrap="true">
</TextView>
<TextView class="h3" [text]="item.get_credit()"></TextView>
<Button class="btn" text="Save" (tap)="change()"></Button>
</StackLayout>
This can be done in many ways, but one common way is by changing visibility of control and binding it to a variable / property in the code behind.
in your component html:
Then on your component ts or code-behind you can handle it in the change method:
class MyComponentSample {
isLabelMode: boolean = true; // Set to true if you want label to show by default or false if TextView as default
change() {
this.isLabelMode = !isLabelMode; // Basically you are toggling the mode here.
}
}
I have a radautocomplete in one of my pages and I'm using bottom-navigation in my app.
The first time I navigate to that page is fine, but after that, when I navigate to that page, the suggestions menu automatically pops open as if I had typed something in the autocomplete but I have not. I even put a textfields above that in my form to steal the focus but that didn't make things any better.
Here is a playground sample
In case playground breaks in the future:
App.vue
<template>
<Page actionBarHidden="true">
<BottomNavigation :selectedIndex="activePage">
<TabStrip>
<TabStripItem>
<label text="0" />
</TabStripItem>
<TabStripItem>
<label text="1" />
</TabStripItem>
</TabStrip>
<TabContentItem>
<button text="go to 1" #tap="activePage=1" />
</TabContentItem>
<TabContentItem>
<StackLayout>
<TextField v-model="textFieldValue" hint="Enter text..."
backgroundColor="lightgray" />
<RadAutoCompleteTextView ref="autocomplete"
:items="choices" backgroundColor="lightgray"
completionMode="Contains" returnKeyType="done"
width="100%" borderRadius="5" />
</StackLayout>
</TabContentItem>
</BottomNavigation>
</Page>
</template>
<script>
import {
ObservableArray
} from "tns-core-modules/data/observable-array";
import {
TokenModel
} from "nativescript-ui-autocomplete";
export default {
data() {
return {
textFieldValue: "",
choices: new ObservableArray(
["one", "two", "three"].map(r => new TokenModel(r))
),
activePage: 0
};
}
};
</script>
<style scoped>
TabContentItem>* {
font-size: 30;
text-align: center;
vertical-align: center;
}
</style>
app.js
import Vue from 'nativescript-vue';
import App from './components/App';
import RadAutoComplete from 'nativescript-ui-autocomplete/vue';
Vue.use(RadAutoComplete);
new Vue({ render: h => h('frame', [h(App)]) }).$start();
I guess the issue is specific to Android, iOS seem to work fine. You may raise an issue at Github, meanwhile a possible workaround is to set visibility on suggestion view on unloaded event, toggle it back on textChanged event.
Updated Playground Sample 1
Update
Changing visibility seems to hide the suggestion view but still occupy the same so components below auto complete field becomes inaccessible. I believe setSuggestionViewHeight(...) may solve this.
Updated Playground Sample 2
Background
I'm using the Admin on rest Datagrid component to render a REST endpoint. Like this:
<Datagrid>
<TextField source="name" />
<TextField source="email" />
<EditButton />
</Datagrid>
The EditButton routes the User to the corresponding edit page. All works great.
Question
But now I'm trying to work out how to route the user to the edit page on row click instead, without using the EditButton.
My attempts
My first idea was to use the rowOption onCellClick.
<Datagrid rowOptions={ {onClick: rowClick } } >
<TextField source="name" />
<TextField source="email" />
</Datagrid>
where the handle function looks like this.
const rowClick = (proxy, event) => {
console.log(proxy, event);
// how to get the resource id??
}
This captures the row click, and the event data is logged to the console. But as far as I can see the click event data doesn't contain information about the REST resource id of the row.
Has someone used the row click event to do something similar?
Or would a better approach be create a new component (for example ClickableField) to wrap the TextField's and add click event handlers in this wrapping component? Like so:
<Datagrid>
<ClickableField><TextField source="name" /></ClickableField>
<ClickableField><TextField source="email" /></ClickableField>
</Datagrid>
As replied by kunal pareek, the accepted answer suggesting to use onRowSelection worked.
Initially I missed the selectable property passed to the TableRow. But when I added that, the selection event was handled. Thus I ended up with this.
<Datagrid rowOptions={{ selectable: true }} options={{ onRowSelection: rowClick }}>
<TextField source="name" />
<TextField source="email" />
</Datagrid>
Material UI table property has an onRowSelection property. You can use this to define and set custom actions when row is selected
http://www.material-ui.com/#/components/table
You can access these properties in the 'options' prop of the AOR datagrid.
If this fails your clickable field idea should work.
On my xml, I have 1 textfield and 1 datepicker. How do I get a datepicker result and storing it result on the textfield?
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="onNavigatingTo">
<StackLayout>
<TextField hint="tanggalprospek" text="{{ tanggalprospek }}" />
<DatePicker day="15" month="5" year="2016" id="date" />
<Button text="Get Tap" tap="{{ getTap }}" />
</StackLayout>
</Page>
Many thanks for your help.. :)
Get the datepicker in the page controller and get the date value of it, then set it to the textfield along with the notifyPropertyChange event. I also use moment.js to have a good date format.
In the xml:
<Button text="Get Tap" tap="getTap" />
In the page controller:
var moment = require("moment");
export function getTap(args) {
var myDatePicker = page.getViewById("date");
var date = moment(myDatePicker.date);
var dateText = date.format("Do MMM [,] H:mm").toString();
page.bindingContext.set("tanggalprospek", dateText);
page.bindingContext.notifyPropertyChange("tanggalprospek", dateText);
}
P/s: I'm using TypeScript
I am using telerik ui for native script. I need a toggle button at top to open the side menu. but I am not able to call the Showdrawer() as per the docs.
What I need is on button click side menu should open. I tried calling RadSideDrawer.prototype.showDrawer(), but failed.
Is there any other side menu available for Nativescript?
main-page.xml
<Page xmlns="http://www.nativescript.org/tns.xsd" xmlns:drawer="nativescript-telerik-ui/sidedrawer" loaded="pageLoaded">
<Page.actionBar>
<ActionBar>
<android>
<NavigationButton text="Go Back" android.systemIcon="ic_menu_moreoverflow" tap="showSideDrawer" />
</android>
</ActionBar>
</Page.actionBar>
<drawer:RadSideDrawer>
<drawer:RadSideDrawer.mainContent>
<StackLayout>
<Label text="{{ mainContentText }}" textWrap="true" />
</StackLayout>
</drawer:RadSideDrawer.mainContent>
<drawer:RadSideDrawer.drawerContent>
<StackLayout cssClass="drawerContent" style="background-color:white;">
<StackLayout cssClass="headerContent">
<Label text="Header" />
</StackLayout>
<StackLayout cssClass="drawerMenuContent">
<Label text="Item 1" style="color:black;" />
<Label text="Item 2" style="color:black;" />
<Label text="Item 3" style="color:black;" />
<Label text="Item 4" style="color:black;" />
</StackLayout>
</StackLayout>
</drawer:RadSideDrawer.drawerContent>
</drawer:RadSideDrawer>
</Page>
getting-started-model.js
var observableModule = require("data/observable");
var GettingStartedViewModel = (function (_super) {
__extends(GettingStartedViewModel, _super);
function GettingStartedViewModel() {
_super.call(this);
this.set("mainContentText", "SideDrawer for NativeScript can be easily setup in the XML definition of your page by defining main- and drawer-content. The component"
+ " has a default transition and position and also exposes notifications related to changes in its state.");
}
return GettingStartedViewModel;
})(observableModule.Observable);
exports.GettingStartedViewModel = GettingStartedViewModel;
function showSideDrawer(args) {
console.log("Show SideDrawer tapped.");
// Show sidedrawer ...
_super.prototype.showDrawer.call(this);
}
exports.showSideDrawer = showSideDrawer;
main page.js
var viewModelModule = require("./getting-started-model");
function pageLoaded(args) {
console.log("Page loaded");
var page = args.object;
page.bindingContext = new viewModelModule.GettingStartedViewModel();
}
exports.pageLoaded = pageLoaded;
You can take a look at this SDK examples that show the main functionality of the RadSideDrawer. As mentioned by #R Pelzer all you need to do is get the instance of the RadSideDrawer for example by using its id:
import drawerModule = require("nativescript-telerik-ui-pro/sidedrawer");
import frameModule = require("ui/frame");
var sideDrawer: drawerModule.RadSideDrawer = <drawerModule.RadSideDrawer>(frameModule.topmost().getViewById("sideDrawer"));
and call its showDrawer() method:
sideDrawer.showDrawer();
Are you calling the showSideDrawer function from code you didn't post? Are you sure you linked the tap button?
<Button tap="showSideDrawer" text="ToggleDrawer"/>
Maybe you can try to give the sideDrawer an Id and use this code.
var drawer = frameModule.topmost().getViewById("sideDrawer");
drawer.showDrawer();
You are getting undefined because no id was assigned to the drawer so to fix your problem assign an id to the sideDrawer <drawer:RadSideDrawer id="sideDrawer"> then you can call
var frame = require('ui/frame');
var drawer = frame.topmost().getViewById("sideDrawer");
function showSideDrawer(){
drawer.showDrawer(); // i prefer using .toggleDrawerState();
};
In my case, I missed inserting , as a result, there was a missing component when toggleDrawer was being called hence the error "TypeError: Cannot read property 'toggleDrawerState' of undefined".
Try inserting all the body component of the xml file in this might solve the issue.
Happy coding :))