Ionic input field and hardware back button

I used ionic framework and build a app,when i put a input field on some view, and make focus in it, the keybord is showing,but when i press the hardware back button, i want it to hide the keyboard,but it close the current view and go back history view, how can i let it to hide keyboard and don`t to close the current view page? if the focus not in the input field,then press back button let it to close current view is normal.

Lets try something else.

Use this code snippet:

$ionicPlatform.onHardwareBackButton(function() {
event.preventDefault();
event.stopPropagation();
alert(‘going back now y’all’);
});

Remove alert, add com.ionic.keyboard plugin close keyboard trigger.

1 Like

i already used com.ionic.keyboard,the keyboard showing normal, i only want to press the hardware back button to hide the keyboard, the keyboard is hided,but the current view is closed too. i want it only hide the keyboard. :sob:

Damn instead of writing a new post I removed old one.

Please, again take a look at my first post :smile:

thks to reply my post, i add these code in my project, and run it , when i press the hardware back button, the current view is closed still, where is error i did?

.run(function($ionicPlatform) {
	$ionicPlatform.ready(function() {
		// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
		// for form inputs)
		if (window.cordova && window.cordova.plugins.Keyboard) {
			cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
		}
		if (window.StatusBar) {
			// org.apache.cordova.statusbar required
			StatusBar.styleDefault();
		}
	});

	$ionicPlatform.onHardwareBackButton(function() {
		//alert('going back now y`all');
		event.preventDefault();
		event.stopPropagation();
		cordova.plugins.Keyboard.close();
	});
})

I need to test this on my own.

thank u very much , i waiting for your reply again.

hi, did u has any new Answer? thks