On Android and iOS, not working "Select All" text in <input type="text"> with ons-sliding-menu - onsen-ui

In case in ons-sliding-menu, both Android(4.4 - 6.0) and iOS(9.3.1) text menu "Select All" don't work correctly.
("Copy", "Cut" and "Paste" work fine.)
See below with Android or iOS.
http://codepen.io/nf_takahashi/pen/oxqbJw
Is that a bug?!
ons.bootstrap();
<ons-sliding-menu main-page="page1.html" menu-page="menu.html" side="left" max-slide-distance="250px" var="menu">
</ons-sliding-menu>
<ons-template id="page1.html">
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="menu.toggleMenu()">
<ons-icon icon="ion-navicon" style="font-size: 32px; width: 1em;"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">Page 1</div>
</ons-toolbar>
<p style="text-align: center; color: #999; padding-top: 100px;"><input type=text></p>
</ons-page>
</ons-template>
<ons-template id="page2.html">
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button onclick="menu.toggleMenu()">
<ons-icon icon="ion-navicon" style="font-size: 32px; width: 1em;"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">Page 2</div>
</ons-toolbar>
<p style="text-align: center; color: #999; padding-top: 100px;">Page2 Contents</p>
</ons-page>
</ons-template>
<ons-template id="menu.html">
<ons-list>
<ons-list-item modifier="chevron" onclick="menu.setMainPage('page1.html', {closeMenu: true})">
page1.html
</ons-list-item>
<ons-list-item modifier="chevron" onclick="menu.setMainPage('page2.html', {closeMenu: true})">
page2.html
</ons-list-item>
</ons-list>
</ons-template>

I would consider this a bug too, since the inputs should remain selectable regardless of the other components. Though it turns out it's created due to bad default values of a library Hammer.js which Onsen 1 uses.
Fixes:
You can remove that option from the default settings before calling ons.bootstrap().
delete Hammer.defaults.behavior.userSelect;
ons.bootstrap();
The other thing which you could do is just remove the disabling:
document.querySelector('ons-sliding-menu').onselectstart = document.querySelector('.onsen-sliding-menu__main').onselectstart = null;
Note that this fix must be executed after the sliding-menu is created/ready. So in your case just wrapping it in ons.ready(function(){ /* fix */ }) was enough.
If you are creating a page with a sliding menu later then you would need to wait for the page init for example and then apply the fix.
Here's a demo where you can see the two fixes in action.
Anyway the first fix is probably easier, but I just came up with the second one initially, so I decided to include that too.

Related

pass value from one ons-template to another using angular js [Onsen UI]

I want some values from one ons-template to another, i have tried sending values from ons-template to controller and getting back to another ons-template from a controller, but is there any way i can get the values directly from one ons-template to another without calling the controller? Below is my code.
sendmoney.html
<ons-template id="sendmoney.html">
<ons-page modifier="shop-details" class='page_bg'>
<ons-toolbar style="background-color: #16A500;">
<div class="left">
<ons-toolbar-button ng-click="menu.openMenu();">
<ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">Send Money</div>
<div class="right">
<ons-toolbar-button onclick="doContactPicker()">
<ons-icon icon="ion-plus" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
</ons-toolbar>
<div ng-controller="getUserContacts">
<ons-list-header>Select Contact</ons-list-header>
<ons-list style="margin: -1px 0">
<div ng-show="loading" class="loading"><img src="img/loading.gif" height="50px" width="50px"></div>
<ons-list-item modifier="chevron" class="list-item" ng-repeat="x in contacts track by $index" style="margin-left: 10px;" ng-click="page.pushPage('sendmoney2.html', {animation: 'slide'});">
<ons-row>
<ons-col width="52px" style="padding: 10px 0 0 0;">
<img src="img/red.png" height="42px" width="42px"/>
</ons-col>
<ons-col>
<header>
<span class="item-title">{{x.name}}</span>
</header>
<p class="swipe-item-desc">{{x.phone}}</p>
</ons-col>
</ons-row>
</ons-list-item>
</ons-list>
</div>
</ons-page>
</ons-template>
I want {{x.name}} and {{x.phone}} in sendmoney2.html template
sendmoney2.html
<ons-template id="sendmoney2.html">
<ons-page modifier="shop-details" class='page_bg'>
<ons-toolbar style="background-color: #16A500;">
<div class="left">
<ons-toolbar-button ng-click="menu.openMenu();">
<ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center">Send Money</div>
</ons-toolbar>
</ons-page>
</ons-template
I don't know Angular very well, but in plain JS, you simply set a global variable to get around this. I think of the app design as just one large web page. That often helps me solve my problems. So basically just define these in the top of your script:
var vName = '';
var vPhone = '';
Then set them in the events, this should work.

Onsen UI navigation not working after adding tabbar

I can't get the navigation to work with the tab bar. I have a list page, search page and details page. For some reason I can't get the list page to persist when navigating either. The details page is never shown even thought I am using app.navi.pushPage('detail.html'). Before adding the tab-bar everything worked fine. Any ideas on what I am doing wrong?
As well, I need to access the detail page from both the list and search pages.
<ons-navigator page="list.html" var="app.navi"></ons-navigator>
<ons-tabbar>
<ons-tab page="favourites.html" label="Favourites" icon="fa-heart"></ons-tab>
<ons-tab page="list.html" label="Near Me" icon="fa-map-marker" active="true"></ons-tab>
<ons-tab page="search.html" label="Search" icon="fa-search"></ons-tab>
</ons-tabbar>
<ons-template id="list.html">
<ons-page id="list-page">
<ons-toolbar>
<div class="center">Near Me</div>
</ons-toolbar>
<ons-list id="lst-estblshmnt"></ons-list>
</ons-page>
</ons-template>
<ons-template id="search.html">
<ons-page id="search-page">
<ons-toolbar>
<div class="center">Search</div>
</ons-toolbar>
<ons-row>
<ons-col>
<input id="srch" type="search" class="search-input">
</ons-col>
<ons-col width="75px" style="display: none">
<ons-button id="btn-cancel-search" modifier="quiet">Cancel</ons-button>
</ons-col>
</ons-row>
<ons-list id="lst-srch"></ons-list>
</ons-page>
</ons-template>
<ons-template id="detail.html">
<ons-page id="detail-page">
<ons-toolbar>
<div class="left"><ons-back-button>Back</ons-back-button></div>
<div class="right">
<ons-toolbar-button id="btn-fllw"><ons-icon icon="fa-heart-o"></ons-icon></ons-toolbar-button>
</div>
</ons-toolbar>
<ons-row>
<ons-col id="establishment-details">
<header>
<center class="item-title">Title</center>
</header>
<div class="item-details">
<ons-row>
<ons-col>
<p class="item-address"></p>
<p class="item-city"></p>
<p class="item-postal_code"></p>
</ons-col>
</ons-row>
</div>
</ons-col>
</ons-row>
</ons-list>
</ons-page>
</ons-template>
You cannot combine <ons-navigator> with <ons-tabbar>. If you use the tabbar element, you can switch pages using setActiveTab(index, [options]). I created a working sample using the template you provided and added a <ons-button> in the list.html template that changes the active page. For more info about the tabbar element, take a look here. Let me know if you need more help :)
<body>
<ons-tabbar var="tabbar">
<ons-tabbar-item
icon="home"
label="Home"
page="list.html"
active="true"></ons-tabbar-item>
<ons-tabbar-item
icon="comment"
label="Comments"
page="search.html"></ons-tabbar-item>
<ons-tabbar-item
icon="gear"
label="Settings"
page="detail.html"></ons-tabbar-item>
</ons-tabbar>
<ons-template id="list.html">
<ons-page id="list-page">
<ons-toolbar>
<div class="center">Near Me</div>
</ons-toolbar>
<ons-list id="lst-estblshmnt"></ons-list>
<ons-button id="btn-switch-search" ng-click="tabbar.setActiveTab(2)">Cancel</ons-button>
</ons-page>
</ons-template>
<ons-template id="search.html">
<ons-page id="search-page">
<ons-toolbar>
<div class="center">Search</div>
</ons-toolbar>
<ons-row>
<ons-col>
<input id="srch" type="search" class="search-input">
</ons-col>
<ons-col width="75px" style="display: none">
<ons-button id="btn-cancel-search" modifier="quiet">Cancel</ons-button>
</ons-col>
</ons-row>
<ons-list id="lst-srch"></ons-list>
</ons-page>
</ons-template>
<ons-template id="detail.html">
<ons-page id="detail-page">
<ons-toolbar>
<div class="left"><ons-back-button>Back</ons-back-button></div>
<div class="right">
<ons-toolbar-button id="btn-fllw"><ons-icon icon="fa-heart-o"></ons-icon></ons-toolbar-button>
</div>
</ons-toolbar>
<ons-row>
<ons-col id="establishment-details">
<header>
<center class="item-title">Title</center>
</header>
<div class="item-details">
<ons-row>
<ons-col>
<p class="item-address"></p>
<p class="item-city"></p>
<p class="item-postal_code"></p>
</ons-col>
</ons-row>
</div>
</ons-col>
</ons-row>
</ons-list>
</ons-page>
</ons-template>
</body>

Onsen UI menu.toggle() is not working after adding navigator with sliding menu

I want to add a page before my sliding menu page. I succeeded to accomplish that. But, now I can't access menu.toggle();
I logged the menu object, that says undefined. And I've also tried navi.menu but that also doesn't seem to work. This is the closest solution I've got but no menu.toggle
Onsen UI - Using Slide-Menu just for specifics pages here is my code
<ons-navigator title="Navigation" var="navi" page="homePage.html">
</ons-navigator>
<ons-template id="homePage.html">
<ons-page ng-controller="mainPageController">
<ons-toolbar>
<div class="center">PHPTRAVELS</div>
<div class="right">
<ons-toolbar-button>Exit</ons-toolbar-button>
</div>
</ons-toolbar>
<ons-row class="home-page">
<ons-col>
<ons-list>
<ons-list-item modifier="tappable"
style="line-height: 25px; font-size: 12px; padding: 5px;"
ng-show="modules[2].status"
ng-click="navi.pushPage('home.html')">
<ons-row>
<ons-col width="70px" class="ic">
<ons-icon icon="fa fa-building" size="50px"></ons-icon>
</ons-col>
<ons-col>
<div class="title">Hotels</div>
<div class="description">Find the perfect hotel room</div>
</ons-col>
</ons-row>
</ons-list-item>
<ons-list-item modifier="tappable" style="line-height: 25px; font-size: 12px; padding: 5px;"
ng-show="modules[6].status || modules[7].status">
<ons-row>
<ons-col width="70px" class="ic">
<ons-icon icon="fa fa-plane" size="50px"></ons-icon>
</ons-col>
<ons-col>
<div class="title">Flights</div>
<div class="description">Get the best flight</div>
</ons-col>
</ons-row>
</ons-list-item>
<ons-list-item modifier="tappable" style="line-height: 25px; font-size: 12px; padding: 5px;"
ng-show="modules[3].status">
<ons-row>
<ons-col width="70px" class="ic">
<ons-icon icon="fa fa-briefcase" size="50px"></ons-icon>
</ons-col>
<ons-col>
<div class="title">Tours</div>
<div class="description">Your vacation awaits</div>
</ons-col>
</ons-row>
</ons-list-item>
<ons-list-item modifier="tappable" style="line-height: 25px; font-size: 12px; padding: 5px;"
ng-show="modules[1].status">
<ons-row>
<ons-col width="70px" class="ic">
<ons-icon icon="fa fa-car" size="50px"></ons-icon>
</ons-col>
<ons-col>
<div class="title">Cars</div>
<div class="description">Seek a deal on wheels</div>
</ons-col>
</ons-row>
</ons-list-item>
<ons-list-item modifier="tappable" style="line-height: 25px; font-size: 12px; padding: 5px;"
ng-show="modules[0].status">
<ons-row>
<ons-col width="70px" class="ic">
<ons-icon icon="fa fa-leanpub" size="50px"></ons-icon>
</ons-col>
<ons-col>
<div class="title">Blog</div>
<div class="description">Travel news portal</div>
</ons-col>
</ons-row>
</ons-list-item>
</ons-list>
</ons-col>
</ons-row>
</ons-page>
</ons-template>
<ons-sliding-menu
menu-page="menu.html" main-page="home.html" side="left"
var="menu" type="reveal" max-slide-distance="260px">
</ons-sliding-menu>
<ons-template id="menu.html">
<ons-page modifier="menu-page">
<br><br>
<ons-list class="menu-list">
<ons-list-item menuitem class="menu-item selected" ng-click="menu.setMainPage('home.html', {closeMenu: true});">
<i class="glyphicon glyphicon-home"></i>
Home
</ons-list-item>
<ons-list-item menuitem class="menu-item" ng-click="menu.setMainPage('browsehotels.html', {closeMenu: true});">
<i class="glyphicon glyphicon-calendar"></i>
Browse Hotels
</ons-list-item>
<ons-list-item menuitem class="menu-item" ng-click="menu.setMainPage('specialoffers.html', {closeMenu: true});">
<i class="glyphicon glyphicon-gift"></i>
Special Offers
</ons-list-item>
<ons-list-item menuitem class="menu-item" ng-click="menu.setMainPage('blog.html', {closeMenu: true});">
<i class="glyphicon glyphicon-th-list"></i>
Blog
</ons-list-item>
<ons-list-item menuitem class="menu-item" ng-click="menu.setMainPage('mybookings.html', {closeMenu: true});">
<i class="glyphicon glyphicon-user"></i>
My Bookings
</ons-list-item>
<ons-list-item menuitem class="menu-item" ng-click="menu.setMainPage('contactus.html', {closeMenu: true});">
<i class="glyphicon glyphicon-map-marker"></i>
Contact Us
</ons-list-item>
</ons-list>
</ons-page>
</ons-template>
<ons-template id="home.html">
<!-- <ons-navigator var="nav"> -->
<ons-page ng-controller="homeController">
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="menu.toggle();">
<ons-icon icon="ion-navicon" size="28px" fixed-width="false"></ons-icon>
</ons-toolbar-button>
</div>
<div class="center text-center">PHPTRAVELS</div>
<div class="right">
<ons-toolbar-button>
<!-- <ons-icon icon="refresh" size="30px" spin="{{isFetching}}" fixed-width="true"></ons-icon> -->
<ons-icon icon="ion-load-c" ng-show="isFetching" spin="{{isFetching}}"></ons-icon>
</ons-toolbar-button>
</div>
</ons-toolbar>
<div>some text</div>
</ons-page>
</ons-template>
The methods toggle(), open() and close() for the sliding menu are deprecated.
You can use the toggleMenu([options]) method instead: http://onsen.io/reference/ons-sliding-menu.html#method-toggleMenu
It seems like you want a page before the sliding menu so I made a small example:
http://codepen.io/argelius/pen/XJOQwy

Using onsen ui split-view with multiple controllers

I am having a problem using my angular js controller on more than one ons-template using split-view navigation.
On the main page it works well, but when i load the second ons-template (that uses the same controller) on the main page it does not work at all.
Please help.
`
<ons-split-view
var="app.splitView"
secondary-page="menu.html"
main-page="search.html"
main-page-width="70%"
collapse="width 500px">
</ons-split-view>
<ons-template id="menu.html">
<ons-page style="background-color: white; border-right: 1px solid #ddd;">
<ons-toolbar>
<div class="center">Menu</div>
</ons-toolbar>
<ons-list>
<ons-list-item
modifier="tappable"
ng-click="app.splitView.toggle(); app.splitView.setMainPage('search.html');">
<i class="ion-search" style="color: #666"></i>
Search
</ons-list-item>
<ons-list-item
modifier="tappable"
onclick="app.splitView.toggle(); app.splitView.setMainPage('mostWanted.html');">
<i class="ion-person-stalker" style="color: #666"></i>
Most Wanted
</ons-list-item>
<ons-list-item
modifier="tappable"
ng-click="app.splitView.toggle(); app.splitView.setMainPage('stolenVehicles.html');">
<i class="ion-model-s" style="color: #666"></i>
Stolen Vehicles
</ons-list-item>
</ons-list>
</ons-page>
</ons-template>
<ons-template id="search.html">
<ons-navigator var="searchNavigator">
<ons-page ng-controller="searchCtrl">
<ons-toolbar>
<div class="center">
<i class="ion-search" style="color: #666"></i>
Search
</div>
</ons-toolbar>
<div style="text-align: center; padding: 60px 10px 10px 10px;">
<section style="padding: 8px">
<b>Enter ID Number</b>
</section>
<section style="padding: 0 8px 8px">
<input type="search" class="search-input" placeholder="Enter ID Number..." style="color:black" ng-model="idNumber"></input>
</section>
<section style="padding: 0 8px 8px">
<ons-button modifier="large" ng-click="getRecords();">Submit</ons-button>
</section>
</div>
</ons-page>
</ons-navigator>
</ons-template>
<ons-template id="record.html">
<ons-navigator var="recordNavigator">
<ons-page ng-controller="searchCtrl">
<ons-toolbar>
<div class="center">
<i class="ion-clipboard" style="color: #666"></i>
Record
</div>
</ons-toolbar>
<div style="text-align: center; padding: 60px 10px 10px 10px;">
<h3>{{record.id}}</h3>
</div>
</ons-page>
</ons-navigator>
</ons-template>
`
JS:
app.controller('searchCtrl', function($scope,data){
$scope.record = null;
$scope.getRecords = function(){
for(var x=0; x<data.person.length; x++){
if($scope.idNumber == data.person[x].id){
$scope.record = data.person[x];
}
}
if($scope.record == null){
alert("No Criminal Record Found");
} else{
searchNavigator.pushPage('record.html');
//console.log($scope.record.id);
}
};
});
If you want the two pages to share the same controller, define the controller on the parent of the "ons-split-view" instead of each page. You can wrap the "ons-split-view" in a div.
For example;
<div ng-controller="searchCtrl">
<ons-split-view
var="app.splitView"
secondary-page="menu.html"
main-page="search.html"
main-page-width="70%"
collapse="width 500px">
</ons-split-view>
</div>

listener for ons-sliding-menu "preopen" event

I am trying to define event listener for ons-sliding-menu "preopen" event. I want setTitle() function of UICtrl controller to be invoked on preopen. Here's my code
app.js
app.controller('UICtrl', function($scope, UIService){
$scope.setMainTitle = function(title) {
UIService.setTitle(title);
}
}
I have tried the following HTML. But the event is not even fired ( i tried to write to console, it is not fired at all)
index.html
<div ng-controller="UICtrl" >
<ons-sliding-menu var="app.slidingMenu" ng-preopen="setMainTitle('test')"
menu-page="menu.html" main-page="main.html" swipable
side="left" type="reveal" max-slide-distance="250px">
</ons-sliding-menu>
</div>
another thing I tried was:
index.html
ons.ready(function() {
app.slidingMenu.on('preopen', function() {
console.log('preopen');
setMainTitle('Test');
} )
});
in this case the event is fired but setMainTitle function is naturally undefined in this scope.
Could someone have a suggestion how to achieve this?
I'm guessing the title is on your main.html??
I tried the same thing but without using angularJS
Look at this sample:
codepen example
JS:
ons.bootstrap();
ons.ready(function() {
menu.on("preopen", function() {
document.getElementById("title").innerHTML = "my title";
});
});
HTML:
<ons-sliding-menu
above-page="page1.html"
behind-page="menu.html"
side="left"
max-slide-distance="250px"
var="menu">
</ons-sliding-menu>
<ons-template id="page1.html">
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button ng-click="menu.toggleMenu()"><ons-icon icon="ion-navicon" style="font-size: 32px; width: 1em;"></ons-icon></ons-toolbar-button>
</div>
<div class="center" id="title">Page 1</div>
</ons-toolbar>
<p style="text-align: center; color: #999; padding-top: 100px;">Page1 Contents</p>
</ons-page>
</ons-template>
<ons-template id="page2.html">
<ons-page>
<ons-toolbar>
<div class="left">
<ons-toolbar-button onclick="menu.toggleMenu()"><ons-icon icon="ion-navicon" style="font-size: 32px; width: 1em;"></ons-icon></ons-toolbar-button>
</div>
<div class="center">Page 2</div>
</ons-toolbar>
<p style="text-align: center; color: #999; padding-top: 100px;">Page2 Contents</p>
</ons-page>
</ons-template>
<ons-template id="menu.html">
<ons-list>
<ons-list-item modifier="chevron" onclick="menu.setAbovePage('page1.html', {closeMenu: true})">
page1.html
</ons-list-item>
<ons-list-item modifier="chevron" onclick="menu.setAbovePage('page2.html', {closeMenu: true})">
page2.html
</ons-list-item>
</ons-list>
</ons-template>

Resources