I am trying to test printing functionality in an app. Am using katzer/cordova-plugin-printer.
I created a button that calls the printer, below is the code I wrote, not sure if its correct:
print(){
Printer.isAvailable().then(
()=>{
Printer.print("<h2>This is just a sample!</h2>").then(
()=>alert('Printing successfull'),
()=>{alert('Unable to print')}
);
},
(reason)=>{
alert('no printer found');
alert(reason)
});
}
I am using an android phone to test
you need to apply the printoptions with an document name.
Printer.print("<h2>This is just a sample!</h2>", { name: 'testdoc' })
Related
For an ionic 2 app to print using Sunmi V1, added native plugin for printer by executing
cordova plugin add cordova-plugin-printer
First I checked whether the printer is available by
checkPrinter() {
this.printer.check().then(function () {
alert("Printer available");
}, function () {
alert("Printer not available");
});
}
It alerts "Printer available"
But the below method doesn't prompt any message
printData() {
this.printer.isAvailable().then(function () {
this.printer.print("Test Data").then(function () {
alert("Printed");
}, function () {
alert("Printing error");
});
}, function () {
alert('Unavailable');
});
}
So I called Printer.print method directly as below
printData(){
this.printer.print("Test Data").then(function () {
alert("Printed");
}, function () {
alert("Printing Error");
});
}
This method opens Print dialog to choose printer
If I select 'All Printers' from the dropdown to select printer instead of 'Save as PDF', then the search screen appears and keeps on searching...
Is some configuration missing or is it possible to interact with POS printers using cordova printer plugin?
Thanks.
i found a new plugin created by labibramadhan. Thanks labib
you can find the plugin here
https://github.com/labibramadhan/cordova-sunmi-inner-printer
First, install by typing ionic
cordova plugin add https://github.com/labibramadhan/cordova-sunmi-inner-printer.git
Then, use it on your cordova javascript codes by calling:
window.sunmiInnerPrinter.printOriginalText("Hello World!")
window.sunmiInnerPrinter.[methods available on here]
https://github.com/labibramadhan/cordova-sunmi-inner-printer/blob/master/www/innerprinter.js
Thank you
"Sunmi printer itself is not a network printer, web applications can not communicate directly with the printer, you need to accept data on the android applications" - From the documents available in their site. (I also contacted their support team but there was no proper reply)
As of now it doesn't support, so I am using github.com/shangmisunmi/SunmiPrinterDemo as example and developing the application in Android instead of ionic 2.
According to the documentation is not that easy:
http://docs.sunmi.com/htmls/index.html?lang=en##V1%20Docs%20&%20Resources
This is a weird issue, that is some what hard to generate and explore.
While building a web-app using Angular, my boss found that all the buttons on the app that are using ng-click directive are not working.
Now, this issue only happens on iphone 6 with IOS 8.3 and using the safari browser.
I can say that when was tested on iPhone5 (All versions), iPhone 6 (IOS 9), Safari for windows and all other browsers (Mobile and desktop), ng-click works like a charm.
The app is being build using Angular 1.4.3.
This is the code for the button, as you can see, nothing special about it:
<button class="btn calculate-button" ng-click="onCalculate()">Calculate</button>
And in the controller:
$scope.onCalculate = function () {
//Do something... And then:
$state.go('someplace');
};
I tried many changes that were suggested here, including ng-touch, ng-bind, building my own click directive as follows:
.directive('basicClick', function($parse, $rootScope) {
return {
compile: function(elem, attr) {
var fn = $parse(attr.basicClick);
return function(scope, elem) {
elem.on('click', function(e) {
fn(scope, {$event: e});
scope.$apply();
});
};
}
};
});
Couldn't find any proper solution for the problem.
Thanks.
IOS 8.4.1 Update has a known issue which stop ng-link and ng-click to work.
Using "touchstart click" can possibly solve this issue.
app.directive("ngMobileClick", [function () {
return function (scope, elem, attrs) {
elem.bind("touchstart click", function (e) {
e.preventDefault();
e.stopPropagation();
scope.$apply(attrs["ngMobileClick"]);
});
}
}])
HTML call: ng-mobile-click="onCalculate()"
I fixed it in the end.
The problem was in the //Do something... And then: part of the function.
At some point along the way, that function saves some data to the browser local storage.
My boss was using private browsing on safari, and apparently when using private browsing on safari, the browser wont save and data on the local storage and it throws an exception and kills the code.
Well, thanks any way.
I have a requirement for a popup to appear with a custom heading (having it appear from index.html on an app just looks tacky).
I tried the suggestion at the end of the following link:
Custom JavaScript alerts in iOS using PhoneGap HTML
So I added the code below to my index.html in the script section:
function showMessage(message, callback, title, buttonName){
title = title || "default title";
buttonName = buttonName || 'OK';
if(navigator.notification && navigator.notification.alert){
navigator.notification.alert(
message, // message
callback, // callback
title, // title
buttonName // buttonName
);
}else{
alert(message);
callback();
}
}
UPDATE
I have the following code for the alert;
if ((inputNumber>maxAllowed))
{
showMessage("The input is too high.",null,"Warning","Warning");
}
After compiling the app, this is not working.
The following is in index.html:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use the PhoneGap API
}
<function shown above is here>
Any idea why this is still not working? Showing from index.html
Thank you.
Kind Regards,
Gary Shergill
This error tells you that function navigator.notification don't exist.
Usually this is because:
Phonegap/Cordova is not initialized inside a HEAD
Function is not initialized inside a deviceready event. Basically function can't be called before cordova.js is fully initialized.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
// Now safe to use the PhoneGap API
}
Here is a function I use while testing Phonegap applications on my PC. I remove it when deploying app on mobile device. It's for confirm function, but you can adjust it for alerting and so on.
// TODO: remove on deploy
navigator.notification = {
confirm: function (message, successCallback) {
successCallback(1);
}
};
You are testing in a browser so navigator.notification is undefined. Also It seems that you added the function showMessage but you are not using it. Try with:
showMessage("The value is too high!", null,"Warning", "Warning");
From phone, notice that the callback is not a string. So in your function, you pass it a string and that is causing it a problem.
http://docs.phonegap.com/en/1.0.0/phonegap_notification_notification.md.html
navigator.notification.alert(
'You are the winner!', // message
alertDismissed, // callback
'Game Over', // title
'Done' // buttonName
);
I see this is the case because I am trying to do this also. So unfortunately you cannot override the callback, and you need to "hard Code" it.
I have add the plugin using CLI like :
$ cordova plugin add cordova-plugin-dialogs
and its working fine for me.
I'm developing an app using Worklight 5.0.6. The app is targeted at tablets (iOS, Android and Windows). The app works fine on iOS and Android, but I'm having trouble getting it to run properly on Windows 8. The app crashes when I click on a link. Here's part of the error message:
"HTML1701: Unable to add dynamic content ' <link/><table></table><a href='/a'>a</a><input type='checkbox'/>'. A script attempted to inject dynamic content or elements previously modified dynamically that might be unsafe. For example, using the innerHTML property to add script or malformed HTML will generate this exception. Use the toStaticHTML method to filter dynamic content or explicitly create elements and attributes with a method such as createElement. For more information, see http://go.microsoft.com/fwlink/?LinkID=247104."
The app is supposed to inject a html fragment when a link is clicked. I'm using the following the following functions to inject html into an element:
function loadPartial(path, elementId)
{
$.get(path, function (data) {
$(elementId).html(data).trigger("create");
$("#my-navbar > ul").removeClass("ui-grid-a");
if (!hideDuringFocus)
{
$("[data-role=header]").fixedtoolbar({ hideDuringFocus: "" });
$("[data-role=footer]").fixedtoolbar({ hideDuringFocus: "" });
}
});
}
function loadPartialWithFunction(path, elementId, aFunction)
{
$.get(path, function (data) {
$(elementId).html(data).trigger("create");
$("#my-navbar > ul").removeClass("ui-grid-a");
if (!hideDuringFocus)
{
$("[data-role=header]").fixedtoolbar({ hideDuringFocus: "" });
$("[data-role=footer]").fixedtoolbar({ hideDuringFocus: "" });
}
aFunction();
});
}
Is there a mistake I made in the code? Any help would be appreciated. Please let me know if more information or source code is needed.
The issue has been resolved, thanks. I have to wrap the code with MSApp.execUnsafeLocalFunction so it'll look this:
function loadPartialWithFunction(path, elementId, aFunction)
{
$.get(path, function (data) {
MSApp.execUnsafeLocalFunction(function(){
$(elementId).html(data).trigger("create");
$("#my-navbar > ul").removeClass("ui-grid-a");
if (!hideDuringFocus)
{
$("[data-role=header]").fixedtoolbar({ hideDuringFocus: "" });
$("[data-role=footer]").fixedtoolbar({ hideDuringFocus: "" });
}
aFunction();
});
});
}
This is an issue with jQuery on Win8 Metro. Metro apps have dynamic content restrictions, that need to be bypassed first. Here is a stack overflow question with lots of answers for this issue:
Using jQuery with Windows 8 Metro JavaScript App causes security error
I'm using Jquery Mobile to develop an web app for Android and iPhone. I want to handle the event when the users change their value in the input text field.
Initially, I use .on("keyup change") and everything seem to work ok. However, when the users paste some text on the text field (by holding and tap on the "Paste"), my event handler is not called.
Please help me if you know how to solve this problem.
Thank you all.
Works on all browsers but not on FireFox.
Demo
$('input').on('paste', function (e) {
if (e.originalEvent.clipboardData) {
var text = e.originalEvent.clipboardData.getData("text/plain");
$('p').empty();
$('p').append(text);
}
});
Credit goes to: jQuery Detect Paste Event Anywhere on Page and "Redirect" it to Textarea
For Android add a timeout as it is in this example http://ajax911.com/numbers-numeric-field-jquery/
For iPad add event 'change' together with paste, worked on iphone
Here is what worked for me on mobile Safari and Chrome.
if (document.getElementById('search_input')) {
document.querySelector('#search_input').addEventListener('paste', (e) => {
let pasteData = (e.clipboardData || window.clipboardData).getData('text');
pasteData = pasteData.replace(/[^\x20-\xFF]/gi, '');
window.setTimeout(() => {
//do stuff
});
});
}