Issue rendering default date on alert in ionic 4 - ionic-framework

I am using Ionic 4 AlertController to create an alert that lets a user add a task. The issue is, that until a user clicks on the date input, no date shows. I have tried adding both a min and max as well.
Code is as follows
async addCustomTask() {
const alert = await this.alertController.create({
header: 'Add custom task',
inputs: [
{
name: 'task',
type: 'text',
placeholder: 'I would like to..'
},
{
name: 'dueDate',
type: 'date'
}
],
buttons: [
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: () => {
return false;
}
}, {
text: 'Ok',
handler: (data) => {
this.addTask(data.task, moment.tz(data.dueDate, this.account.timezone));
}
}
]
});
await alert.present();
};
Looks like this when it loads up
The moment you click it, it all begins to work as needed. It submits as a date as well, in the correct format.
Ionic:
ionic (Ionic CLI) : 4.10.3 (/Users/sam/.nvm/versions/node/v11.0.0/lib/node_modules/ionic)
Ionic Framework : #ionic/angular 4.0.0-rc.0
#angular-devkit/build-angular : 0.8.9
#angular-devkit/schematics : 0.8.9
#angular/cli : 6.2.9
#ionic/angular-toolkit : 1.2.2
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib#8.1.1)
Cordova Platforms : ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.4.0, (and 11 other plugins)
System:
NodeJS : v11.0.0 (/Users/sam/.nvm/versions/node/v11.0.0/bin/node)
npm : 6.4.1
OS : macOS Mojave
Xcode : Xcode 10.1 Build version 10B61

My Current Ionic version is 4.12.0, needed an alert-popup to take input from user StartDate and EndDate from the user for a filter. What I learned is that it allows you to add the "date" type HOWEVER, it only supports "STRING" for value & max values. Also, remember not to mix the input types. The following is my code
private format_date(dt: any) {
var today = new Date(dt);
let dd: any = today.getDate();
let mm: any = today.getMonth() + 1;
const yyyy = today.getFullYear();
if (dd < 10) {
dd = `0${dd}`;
}
if (mm < 10) {
mm = `0${mm}`;
}
return `${yyyy}-${mm}-${dd}`;
}
async presentPopover() {
const dt = new Date();
this.firstDate = dt.getFullYear() + '-' + ((dt.getMonth() + 1) < 10 ? '0' + (dt.getMonth() + 1) : (dt.getMonth() + 1) ) + '-01';
this.maxDate = this.format_date(dt);
this.lastDay = new Date(dt.getFullYear(), dt.getMonth() + 2, 0);
this.lastDay = this.format_date(this.lastDay);
if(new Date(this.lastDay) > dt) {
this.lastDay = this.format_date(dt);
}
const alerts = await this.alertController.create({
header: 'Filter',
inputs: [
{
name: 'fromDt',
type: 'date',
value: this.firstDate,
max: this.maxDate
},
{
name: 'toDt',
type: 'date',
value: this.lastDay,
max: this.maxDate
}
],
buttons:
[
{
text: 'Cancel',
role: 'cancel',
cssClass: 'secondary',
handler: () => {
console.log('Confirm Cancel');
}
},
{
text: 'Ok',
handler: () => {
console.log('Confirm Ok');
this.fetchData();
}
}
]
});
await alerts.present();
}

Related

Use ion-datetime v4 instead of v6

I am working on an ionic project that was primarily built using v4 of the ionic framework.
After a recent change in my system setup I'm not able to display my datetime component as it was under ionic v4
I would like to display my date time as following:
Instead of what it is now:
How to force ionic to use v4 component instead of v6 ?
After looking for a good idea and keeping the version of ionic, you can use the multipicker as a date picker, I know it's not the best solution, but is the closer way to do it with the same view, here is an example of day - month picker
Put in your html:
<ion-item>
<ion-input type="">{{pdate}}</ion-input>
</ion-item>
<ion-button expand="block" (click)="presentPicker()">Show Picker</ion-button>
Put in your controller:
private pdate: string;
constructor(private pickerController: PickerController) { }
...
async presentPicker() {
const picker = await this.pickerController.create({
buttons: [
{
text: 'Confirm',
handler: (selected) => {
this.pdate = selected.day.value +selected.month.value ;
},
}
],
columns: [
{
name: 'day',
options: [
{ text: '01', value: '01' },
{ text: '02', value: '02' },
{ text: '03', value: '03' },
]
},
{
name: 'month',
options: [
{ text: 'Jan', value: '01' },
{ text: 'Feb', value: '02' },
{ text: 'Mar', value: '03' },
]
}
]
});
await picker.present();
}
you need to install ionic v4 follow this command
npm install -g ionic#5.0.0

Ionic capacitor Camera, File plugin_not_install

Ionic Framework : #ionic/angular 5.5.2
#angular-devkit/build-angular : 0.1100.7
#angular-devkit/schematics : 10.0.8
#angular/cli : 10.0.8
#ionic/angular-toolkit : 2.3.3
Capacitor:
Capacitor CLI : 2.4.5
#capacitor/core : 2.4.5
Utility:
cordova-res : not installed
native-run : 1.3.0
I've been trying to let the user add images from the camera or gallery using this tutorial
(https://enappd.com/blog/camera-and-image-picker-in-ionic-apps/148/). When I run the application on the emulator, the error message (from ToastController) said 'plugin_not_installed'.
page1.ts
import { Camera, CameraOptions } from "#ionic-native/Camera/ngx";
import { File } from "#ionic-native/file/ngx";
export class Page1 extends OnInit(){
constructor(
private camera: Camera,
private actionSheetController: ActionSheetController,
private file: File
){}
async pickImage(sourceType) {
const options: CameraOptions = {
quality: 100,
sourceType: sourceType,
destinationType: this.camera.DestinationType.FILE_URI,
encodingType: this.camera.EncodingType.PNG,
mediaType: this.camera.MediaType.PICTURE,
};
await this.camera.getPicture(options).then(
(imageData) => {
console.log(imageData);
// imageData is either a base64 encoded string or a file URI
if (imageData !== undefined)
this.img = "data:image/jpeg;base64," + imageData;
},
(err) => {
this.presentToast(err);
}
);
}
async selectImage() {
const actionSheet = await this.actionSheetController.create({
header: "Select Image source",
buttons: [
{
text: "From Gallery",
handler: () => {
this.pickImage(this.camera.PictureSourceType.PHOTOLIBRARY);
},
},
{
text: "From Camera",
handler: () => {
this.pickImage(this.camera.PictureSourceType.CAMERA);
},
},
{
text: "Cancel",
role: "cancel",
},
],
});
return await actionSheet.present();
}
page1.html
<ion-card id="pictureFrame" (click)="selectImage()">
</ion-card>
downgrading to "onesignal-cordova-plugin": "^2.11.4" worked for me

ionic 3 pdfmake not working in mobile device

In my application,there is a screen for generating PDF .In web browser, the PDF is getting downloaded, content is displayed but in the mobile it is getting downloaded and saved in PDF format and the content is not getting written to the PDF.
Plugin used: cordova pdfMake
Here is the code for reference
createPdf(val1,val2,val3) {
this.Descr=val1;
this.ValueDescr=val2;
this.VisionDescr=val3;
var docDefinition = {
content: [
{ text: 'Family Description', style: 'header' },
{ },
{ text: 'Family History :', style: 'subheader' },
{ text: this.Descr ,style: 'story', margin: [20, 0, 0, 30] },
{ text: 'Family Values :', style: 'subheader' },
{ text: this.ValueDescr ,style: 'story', margin: [20, 0, 0, 30]},
{ text: 'Family Vision :', style: 'subheader' },
{ text: this.VisionDescr ,style: 'story', margin: [20, 0, 0, 30] },
],
styles: {
header: {
fontSize: 18,
bold: true,
alignment: 'center',
},
subheader: {
fontSize: 14,
bold: true,
margin: [0, 15, 0, 0]
},
story: {
fontSize: 12,
width: '50%',
}
}
}
if(this.Descr || this.ValueDescr || this.VisionDescr)
{
this.pdfObj = pdfMake.createPdf(docDefinition);
// alert("PDF has been created successfully.Kindly wait for it to be downloaded...")
this.downloadPdf(this.pdfObj);
}
}
downloadPdf(val) {
this.pdfObj = val;
if (this.platform.is('cordova')) {
this.pdfObj.getBuffer((buffer) => {
var blob = new Blob([buffer], { type: 'application/pdf' });
// Save the PDF to the data Directory of our App
this.file.writeFile(this.file.externalDataDirectory, 'familydescription.pdf', blob, { replace: true }).then(fileEntry => {
// Open the PDf with the correct OS tools
this.fileOpener.open(this.file.externalDataDirectory + 'familydescription.pdf', 'application/pdf');
})
});
} else {
// On a browser simply use download!
this.pdfObj.download();
}
}
Ionic Information
Ionic:
ionic (Ionic CLI) : 4.2.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
#ionic/app-scripts : 3.2.0
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib#8.1.1)
Cordova Platforms : android 7.1.2, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 1.1.1, (and 30 other plugins)
System:
Android SDK Tools : 26.1.1 (/Users/aligntech/Library/Android/sdk/)
ios-deploy : 1.9.4
NodeJS : v10.13.0 (/usr/local/bin/node)
npm : 6.4.1
OS : macOS
Xcode : Xcode 10.1 Build version 10B61
I found the solution for the above problem I posted it. I solved it by handling it in a different way
createPdf(val1,val2,val3) {
let self = this;
this.Descr=val1;
this.ValueDescr=val2;
this.VisionDescr=val3;
var docDefinition = {
content: [
{ text: 'Family Description', style: 'header' },
{ },
{ text: 'Family History :', style: 'subheader' },
{ text: this.Descr ,style: 'story', margin: [20, 0, 0, 30] },
{ text: 'Family Values :', style: 'subheader' },
{ text: this.ValueDescr ,style: 'story', margin: [20, 0, 0, 30]},
{ text: 'Family Vision :', style: 'subheader' },
{ text: this.VisionDescr ,style: 'story', margin: [20, 0, 0, 30] },
],
styles: {
header: {
fontSize: 18,
bold: true,
alignment: 'center',
},
subheader: {
fontSize: 14,
bold: true,
margin: [0, 15, 0, 0]
},
story: {
fontSize: 12,
width: '50%',
}
}
}
if(this.Descr || this.ValueDescr || this.VisionDescr)
{
this.pdfObj = pdfMake.createPdf(docDefinition);
pdfMake.createPdf(docDefinition).getBuffer(function (buffer) {
let utf8 = new Uint8Array(buffer);
let binaryArray = utf8.buffer;
self.saveToDevice(binaryArray,"familydescription.pdf")
});
// this.downloadPdf(this.pdfObj);
}
}
saveToDevice(data:any,savefile:any){
let self = this;
self.file.writeFile(self.file.externalDataDirectory, savefile, data, {replace:false});
const toast = self.toastCtrl.create({
message: 'File saved to your device',
duration: 3000,
position: 'top'
});
toast.present();
}
and I found an issue the bug is with file opener which I used in previous code!
I Referred above code from this website https://medium.com/#rakeshuce1990/ionic-how-to-create-pdf-file-with-pdfmake-step-by-step-75b25aa541a4 use this link for detailed reference.

Setting params in Kendo UI Grid when calling a rest service [Workaround]

I have a Kendo UI Grid that is calling a rest service. It works fine, as long as I do not try to use any params.
I know the the rest service is correct, as I can call it from a browser, and get correct results [depending on the param I send]. Also, when I look the server log I see that it is calling the rest service with no params.
My code is below:
document).ready( function() {
var crudServiceBaseUrl = "rsPC.xsp",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/PCByStatus",
filter: {field: "status", value: "2" }
dataType: "json",
update: {
url: crudServiceBaseUrl + "/PC/Update",
dataType: "json"
},
destroy: {
url: crudServiceBaseUrl + "/PC/Destroy",
dataType: "json"
},
create: {
url: crudServiceBaseUrl + "/PC/Create",
dataType: "json"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
scrollable: {
virtual: true
},
height: 543,
schema: {
model: {
id: "PCId",
fields: {
PCId: {type:"string"},
serialNumber: {type: "string"},
officeLoc: {type: "string"},
unid: {type:"string"},
model: {type:"string"},
checkInDate: {type: "string"}
}
}
}
});
// Grid
grid = $("#grid").kendoGrid( {
dataSource: dataSource,
columns : [ {
field : "serialNumber",
title : "Serial Number"
}, {
field : "model",
title : "Model"
}, {
field : "officeLoc",
title : "Office Location"
}, {
field : "checkInDate",
title : "Check In Date",
template: "#= kendo.toString(kendo.parseDate(checkInDate, 'yyyy-MM-dd'), 'MM/dd/yyyy') #"
} ],
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
dataBound : addExtraStylingToGrid,
reorderable : true,
filterable : true,
scrollable : true,
selectable : true,
sortable : true,
});
I still cannot get this to work and am a bit stumped.
I have two rest services, one returns all data, one takes "status" as a part and return a subset of the data that equals the parm.
The URL is:
http://localhost/scoApps/PC/PCApp.nsf/rsPC.xsp/PCByStatus?status=2
When entered into browser I get the correct number of records.
So I changed the code (see below). I have included all of the code for the CSJS:
$(document).ready( function() {
// Double Click On row
$("#grid").on(
"dblclick",
" tbody > tr",
function() {
var grid = $("#grid").data("kendoGrid");
var row = grid.dataItem($(this));
window.location.replace("xpFormPC.xsp" + "?key=" + row.unid + "target=_self");
});
// Add hover effect
addExtraStylingToGrid = function() {
$("table.k-focusable tbody tr ").hover( function() {
$(this).toggleClass("k-state-hover");
});
};
// Search
$("#search").keyup( function() {
var val = $('#search').val();
$("#grid").data("kendoGrid").dataSource.filter( {
logic : "or",
filters : [ {
field : "serialNumber",
operator : "contains",
value : val
}, {
field : "officeLoc",
operator : "contains",
value : val
}, {
field : "model",
operator : "contains",
value : val
} ]
});
});
var crudServiceBaseUrl = "rsPC.xsp",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/PCByStatus",
dataType: "json"
},
update: {
url: crudServiceBaseUrl + "/PC/Update",
dataType: "json"
},
destroy: {
url: crudServiceBaseUrl + "/PC/Destroy",
dataType: "json"
},
create: {
url: crudServiceBaseUrl + "/PC/Create",
dataType: "json"
},
parameterMap: function(options, operation) {
if (operation == "read"){
options.field = "status"
options.value = "2"
return options;
}
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
scrollable: {
virtual: true
},
height: 543,
schema: {
model: {
id: "PCId",
fields: {
PCId: {type:"string"},
serialNumber: {type: "string"},
officeLoc: {type: "string"},
unid: {type:"string"},
model: {type:"string"},
checkInDate: {type: "string"}
}
}
}
});
// Grid
grid = $("#grid").kendoGrid( {
dataSource: dataSource,
columns : [ {
field : "serialNumber",
title : "Serial Number"
}, {
field : "model",
title : "Model"
}, {
field : "officeLoc",
title : "Office Location"
}, {
field : "checkInDate",
title : "Check In Date",
template: "#= kendo.toString(kendo.parseDate(checkInDate, 'yyyy-MM-dd'), 'MM/dd/yyyy') #"
} ],
pageable: {
refresh: true,
pageSizes: true,
buttonCount: 5
},
dataBound : addExtraStylingToGrid,
reorderable : true,
filterable : true,
scrollable : true,
selectable : true,
sortable : true
});
// Edit
function onEdit(e) {
}
// Change
function onChange(args) {
var model = this.dataItem(this.select());
ID = model.ID;
}
;
});
What am I doing wrong?
=========================================
I have a workaround. Or possibly this is the way it is supposed to be done.
var crudServiceBaseUrl = "rsPC.xsp", dataSource = new kendo.data.DataSource(
{
transport : {
read : {
url : crudServiceBaseUrl
+ "/PCByStatus?status=2",
dataType : "json"
},
Now I just construct the URL I want. Not so elegant I suppose, but it works.
I have a workaround. Or possibly this is the way it is supposed to be done.
var crudServiceBaseUrl = "rsPC.xsp", dataSource = new kendo.data.DataSource(
{
transport : {
read : {
url : crudServiceBaseUrl
+ "/PCByStatus?status=2",
dataType : "json"
},
Filter is used for client side data unless you set serverFiltering to true.
Here is the filter kendo documentation and the serverFiltering documentation.
I use parameterMap when I need to send parameters that are not created by filtering the control that I'm using. The kendo documentation provides an example using parameterMap.
Here is an example of how I've used it in the past:
var appsDataSource = new kendo.data.DataSource({
transport: {
read: {
url: apiUrl + "App"
},
parameterMap: function (data, action) {
if (action === "read") {
data.lobid = lobId;
data.parent = isParent;
return data;
} else {
return data;
}
}
}
});
Try changing the parameterMap:
parameterMap: function(options, operation) {
if (operation == "read"){
options.field = "status";
options.value = "2";
return options;
}
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
and update the read definition to remove filter. One thing to consider is that you are not returning anything from the read method if it doesn't meet the criteria of not being a read and options is not null. That leaves out any other combination that isn't obviously handled in your existing code.

How to pass selected Value form Popup to normal controller page in ionic framework

How to pass selected Value form Popup to normal controller page in ionic framework
`$scope.showprofpopup = function()
{
$scope.data = {}
var myPopup = $ionicPopup.show
({
templateUrl: 'templates/popover.html',
title: 'Please Choose Category',
scope: $scope,
buttons: [ { text : 'Cancel' }, { text: 'Select', type: 'button-dark', onTap: function(e) { return $scope.data; } }, ]
});
myPopup.then(function(res)
{
//$scope.create(res.category);
//$state.go('app.userdetails');
//$scope.contactMessage = { text: res };
if(!res.category)
{
$ionicLoading.show({ template: '<ion-spinner icon="android"></ion-spinner>', animation: 'fade-in', showBackdrop: true, maxWidth: 100,showDelay: 50 });
$scope.showprofpopup();
$timeout(function () { $ionicLoading.hide(); }, 3000);
//$ionicPopup.alert({ title: "Please Choose Category" });
}
else
{
$scope.SelectedProfessional = { text: res.category};
//alert(res.category);
$state.go('app.userdetails');
}
});
};`
I want to send the result re.category to app.userdetails page.kindly anyone help me.
using $stateParams
$state.go('app.userdetails',{'category': res.category});