I am working on a web app where, I have a Common popup as a direct child of , it contains few popups created dynamically from the JSON. There are two separate pages having user input form. JSON file is updated using the form data.
I am updating the contents of the popups using the updated JSON in the form submit function. I am facing the problem to refresh the popup contents on form submit. I have to restart the APP to see the changes on popups.
I tried triggering 'refresh' and 'create' events on popups in form submit function, but still no result.
Moreover even if I set the contents of popup div to be empty using $('#popup-div').empty() in submit function, I can still see the popup. Don't know if this is the caching problem.
Please advice for some solution, Thanks
Example Code:
<body>
<div id="common-popup">
<div id="data-popup" data-role="popup">';
<p>Name: N/A<p>
<p>DOB: N/A <p>
</div> <!--Popup div ends -->
</div>
<div data-role="page" id="page1">
<input type='text' id='p1_name' value=''>Name: </input>
<input type='text' id='p1_dob' value=''>DOB: </input>
<button class="update-data" id="b1"/>
Watch Data
</div>
<div data-role="page" id="page2">
<input type='text' id='p2_name'>Name: </input>
<input type='text' id='p2_dob'>DOB: </input>
<button class="update-data" id="b2"/>
Watch Data
</div>
</body>
<script type="text/javascript">
$('.update-data').on('vclick', function(){
var id = $(this).id;
id = id.split('');
var htm = '<div id="data-popup" data-role="popup">';
htm += '<p>Name: ' + $('#p' + id[1] + '_name').val() +'<p>';
htm += '<p>Name: ' + $('#p' + id[1] + '_name').val() +'<p>';
$('#common-popup').html(htm).trigger('create');
});
</script>
Here is the working demo
$( "#common-popup #data-popup")
.enhanceWithin().popup()
.on('popupafterclose', function(event) {
$(this).remove();
});
JS Fiddle Demo
The dynamic popup created should be removed after its closed. Creating it again and again makes multiple popups..but you are still referring to the first one, which created the problem.
Related
I am new with ionic framework.Currently i am working on ionicsidemenu app. I want to show records according to date, having date as heading and respective date having multiple records.
For this i have two web services one is for heading date another is for date-wise records. In my HTML file i have two ng-repeat one is for display heading date. Now i am not able to understand how to get records of particular date as date has to be sent to web service for getting records.
I have tried this:
<div ng-repeat="d in dates track by $index">
<h2>d.edate</h2>
<div ng-init="datewiserecords(d.edate);" >
<div ng-repeat="n in res1 track by $index" class="text-white" >
</div></div></div>
but its not working.Please help me.
I am not sure what you are looking for, but the way I understand the question makes me to give you a solution as below:
My Solution:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
<ul>
<li ng-repeat="get_date in dates">
<h2>{{get_date.date}}</h2>
<h4>{{get_date.data}}</h4>
</li>
</ul>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.dates = [{date:"1",data:"One"},{date:"2",data:"Two"},{date:"3",data:"Three"}];
});
</script>
</body>
</html>
Hope This is helpful
I am trying to implement a switch element using onsen ui to enable/disable BT and having trouble talking to the controller js.
<script>
var app = angular.module('app', ['onsen']);
app.controller('Controller', function($scope) {
$scope.item=[{selected:true}];
$scope.enBT = function(){
var Checked = BTSwitch.isChecked();
alert(Checked);
}
}
</script>
Below is my HTML code.
<div class="app">
<h1 >Apache Cordova using Onsen</h1><br /><br />
<ons-span id="enBluetooth" style="font-size: 40"> Enable bluetooth
<label class="switch">
<input type="checkbox" var="BTSwitch" ng-model="item.selected" ng-change="enBT" class="switch__input">
<div class="switch__toggle"></div>
</label>
</ons-span><br />
</div>
The switch UI displays but I cannot get it to respond to ng-change nor does it show the startup state as true, which is set in JS. Please can someone tell me what I am doing incorrectly? Thanks for your help!
First, you need to set ng-app attribute in the wrapper element, or call angular.bootstrap(document, ['app']), to run the app.
Second, you need to set ng-controller attribute in the wrapper element to bind the controller to the view.
Third, $scope.item doesn't need to be an array. Just $scope.item = {selected: true} is enough.
And there are a few other mistakes in your code. Try below snippet.
var app = angular.module('app', ['onsen']);
app.controller('Controller', function($scope) {
$scope.item= {selected:true};
$scope.enBT = function(){
var Checked = $scope.item.selected;
alert(Checked);
};
});
<link href="https://cdn.rawgit.com/OnsenUI/OnsenUI/1.3.6/build/css/onsen-css-components.css" rel="stylesheet"/>
<link href="https://cdn.rawgit.com/OnsenUI/OnsenUI/1.3.6/build/css/onsenui.css" rel="stylesheet"/>
<script src="https://cdn.rawgit.com/OnsenUI/OnsenUI/1.3.6/build/js/angular/angular.min.js"></script>
<script src="https://cdn.rawgit.com/OnsenUI/OnsenUI/1.3.6/build/js/onsenui.min.js"></script>
<div ng-app="app" class="app" ng-controller="Controller">
<h1 >Apache Cordova using Onsen</h1><br /><br />
<ons-span id="enBluetooth" style="font-size: 40"> Enable bluetooth
<label class="switch">
<input type="checkbox" var="BTSwitch" ng-model="item.selected" ng-change="enBT()" class="switch__input">
<div class="switch__toggle"></div>
</label>
</ons-span><br />
</div>
I have multiple pages in my one html file.
I trying to implement the pageinit event handler on the second data-role="page".
So I declared pageinit inside it's specific data-role="page".
<div data-role="page" id="foo3" data-dom-cache="false">
<script>
$(document).on('pageinit','#foo3' , function(){
abcsong_file_path = '/android_asset/www/audio/abcsong.mp3';
my_abc = new Media(abcsong_file_path);
my_abc.play();
var i =0;
var time;
function my_loop(){
setTimeout(function (){
var my_alphabets = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"];
$('#content_loop2').append('<img src="img/alphabets/'+my_alphabets[i]+'.png" />');
i++;
time = 700;
if(i<26)
{
my_loop();
}
}, time)
}
my_loop();
});
</script>
<div data-role="header" data-theme="b">
</div>
<div data-role="content" >
<div id="content_loop2" data-inset="true">
</div>
</div>
<div data-role="footer" >
</div>
</div>
What I expected was that it would initialize everytime I visit this page. But it runs correctly only the first time I open it. Every other time it just show the output of previously executed code.
Please help me how to go about it.
Pageinit should run only once, it was made to be just like document ready.
If you want your code to run every time page is visited then use pageshow or pagebeforeshow.
Read more about it here.
Pageinit should fire only once, according to the docs, but at least in previous versions that was not the actual truth.
I am currently using jQM 1.3.2 and no longer experiencing this problem on Android or in desktop browser. Pay attention to it though, especially if you are also using Phonegap.
Document pageinit fires more than once on iOS (jQueryMobile)
I am using mobile Jquery, phonegap to develop a mobile application.
Upon selectioin of item, I am generating a new dynamic page;
with data-role="page" and id="bar"
So my code becomes like this.
<script type="text/javascript" >
function showCategory( urlObj, options )
{
var alphaName = urlObj.hash.replace( /.*aplha=/, "" ),
var $page = $('<div data-role="page" id="bar">
<div data-role="content"> <a href="#bar?aplha='+previous+'>'+previous+'</a>
<img src="img/alphabets/'+alphaName+'.png" onclick="playAudio('+alphaName+')" />
'+next+'
</div> <div data-role="footer" data-position= "fixed"> <h4>
Back to Categories</h4> </div> </div>');
}
</script>
I have tried almost everything to get the alert on alphaName on onclick=playAudio but all in vian. I know the problem is in giving qoutes, but somewhow I cannot figure the right way.
If anyone could help please
Try "on" bind method
As of Jquery 1.7+ the better approach is to use on method.
$(document).on('click', 'img', function ()
{
alert('image is clicked')
});
Thanks
AB
I have added zxing barcode scanner plugin successfully in my android phonegap app here is js code where on page show I am able to see barcode scanner screen.
$('#scanpage').live('pageshow', function (event, ui) {
//navigator.notification.alert("Search page");
window.plugins.barcodeScanner.scan( function(result) {
//navigator.notification.alert("We got a barcode\n" + "Result: " + result.text + "\n" +"Format: " + result.format + "\n" +
// "Cancelled: " + result.cancelled);
}, function(error) {
navigator.notification.alert("Scanning failed: " + error);
});
});
here is html5 page code
div id="scanpage" data-role="page">
<div data-role="header" class="pageheader">
<div class="height30" style="padding-right:2%;">
<div class="back" style="margin-right:2%;">Back</div>
<div class="logo2" ><a href="#" ><img src="images/scan.png" style="padding-top:12px;" alt="Scan Code" /></a>
</div>
</div>
</div>
<div data-role="content" class="wrapper" style="width:100%">
<div style="background-color:#000000;" >
<div style="height:400px;" id="scanarea"></div>
<input name="" type="button" class="button" value="Focus and Scan" data-role="none" />
</div><!-- inner div-->
</div>
</div> <!-- end SCAN PAGE -->
BUT how it works, when I open the page firstly load html but in second whole screen is covered with bar-code scanner window I want to fix this scan area in a DIV 'scanarea' . But don't know how to fix it in certain div area and on button click scanning will perform and read the barcode.
scan window
html page
need to show like this
The barcode scanning screen is implemented as Android activity which hides PhoneGap's web view completely. If you want to customize this screen, you may want to change its layout file somehow.
I assume that your button "Focus and scan" should trigger a manual scan (the default is to recognize the first barcode, I think) – therefore you may have to change the activity implementation to include a handler for that button.
See also Simon Mac Donald's blog (he seems to be developing the barcode scanning plugin on Android) and this answer (which is exactly what I wrote above, snap :P).