I’m using Ionic 4 with Angular 8
I want to “Disable” modal dismiss when i press android hardware “back” button.
this.platform.backButton.subscribe(() => {
console.log("Button Pressed");
});
I can trace the event but i can’t prevent ionic to dismiss modal.
just add ModalOption backdropDismiss: false
this.platform.backButton.subscribe(async () => {
console.log("Button Pressed");
if (this.modalCtrl.getTop()) {
const modal = await this.modalCtrl.getTop();
if (modal) {
console.log('ModalCtrl Top');
return;
}
}
});
Related
I am making a sign-up form. My problem is when the user fills the last field in my form and hit enter on the keyboard, but the keyboard does not dismiss. Is there any way to dismiss the keyboard?
If you want to dismiss the keyboard when the user clicks anywhere on the screen:
wrap the scaffold with GestureDetector:
GestureDetector(
onTap: () {
setState(() {
FocusScope.of(context).requestFocus(new FocusNode());
});
},
child: Scaffold());
If you want to dismiss the keyboard when the user fills the last textField:
track the textfields controllers and when you are at the last one use yourControllerName.unfocus();
Clicking on 'OK' automatically dismisses the alert. I want to add some logic inside 'OK' click handler and then decide if I want to dismiss the alert or not.
let inputsAlert = this.alertCtrl.create({
...
buttons: [
{
text: 'OK',
handler: inputsData => {
// Some logic here
if (canDismiss) {
this.inputsAlert.dismiss();
} else {
// Do nothing
}
}
}
]
})
In the array of buttons, each button includes properties for its text, and optionally a handler. If a handler returns false then the alert will not automatically be dismissed when the button is clicked.
From https://ionicframework.com/docs/api/alert#buttons
Simply return false if you do not want the alert to be dismissed.
I used the popover interface on <ion-select> to display pop-over. In an Android device, if the user taps on ion-select but didn't select any option and click the hardware back button, it moves to the previous view but popover interface is still visible. Please help.
<ion-select interface="popover" [(ngModel)]="item.productType" placeholder="Please select" multiple="false" ionChange="onChange($event)" >
<ion-option *ngFor="let opt of options" [value]="opt.value">{{opt.label}}</ion-option>
</ion-select>
Define page name in modal page.
pageName = "ModalPage";
Then register backbutton in app.component.ts
this.platform.registerBackButtonAction(() => {
let nav = this.app.getActiveNav();
let view = nav.getActive().instance.pageName;
if (view == 'ModalPage') {
let activeView: ViewController = nav.getActive();
activeView.dismiss();
} else {
this.nav.pop();
}
}
Basically it will register your device backbutton to perform action when particular modal opened.
Feel free to comment for more help :)
Is that possible to implement the native transition or animation (opacity etc) in alert controller like what we are doing in Modal dialog?
For modal dialog we can use like below code.
let modal = this.modalCtrl.create(SingleButtonAlertModalPage, { showBackdrop: false,
enableBackdropDismiss: false,
enterAnimation: 'modal-scale-up-enter'});
I want to implement fade in/out in alert controller. While alert dialog displaying it has to come from top of the screen? Is that possible ?
You can apply custom styles to ModalController by adding cssClass.
{ cssClass: 'native-transition' }
In your component.scss file, apply the properties to class for animation.
.native-transition{
opacity: 0.5;
}
I am creating a popup message and show this popup over an action from a button.
Now I am trying to dismiss the SplitViewController, on that the popup is shown, from the popup callback.
But in my case it fails, so how is the right way to do this?
function showPopUp
{
var popup = vMobileController.solutionController().createPopUp();
popup.setMessage("Testmessage?");
popup.setTitle("test");
popup.addOption("yes",popupYES);
popup.addOption("no",popupNO);
popup.show();
}
function popupNO()
{
var vSolutionController = vMobileController.solutionController();
var vDatamanager = vMobileController.dataManager();
var vLogger = vMobileController.logger();
var currViewC = vSolutionController.rootViewController().firstSubViewControllerByName("overview_split");
currViewC.dismissModal();
}
function popupYES()
{
}
A modal presented controller is never a sub controller of the root view controller. To access modal presented controllers use the accessing methods of the solution controller itself.
var vSolutionController = mobileController.solutionController();
var vControllertoDismiss = vSolutionController.findFirstViewController("overview_split");
if (vControllertoDismiss) {
vControllertoDismiss.dismissModal();
} else {
logger.debug("Coun't find controller overview_split");
}
If this also not find your controller you might misspelled the controllers name? Use Screens.overview_split to let the ACK autocomplete the screen name.
var vControllertoDismiss = vSolutionController.findFirstViewController(Screens.overview_split);