How to close the native keyboard when calling searchbar.disable()

I have a map page in my app in which I listen for online and offline Cordova network events. In the case of going offline I want to disable mostly all the UI on the page except one navbar button.
This involved disabling the searchbar, and for this I have two questions:

• How do I force the native keyboard to close as well when I call searchbar.disable()? - if a search had commenced before network was lost, I can disable the searchbar but the keyboard and cursor remain.

• How do I hide and show the searchbar-icon in the correctly intended way?

.offline-only,
html.device-offline .online-only {
  display:none;
}

.online-only,
html.device-offline .offline-only {
  display:block;
}
<div class="online-only">online</div>
<div class="offline-only">offline</div>
Dom7(window).on('online',function(){
  Dom7('html').removeClass('device-offline');
});
Dom7(window).on('offline',function(){
  Dom7('html').addClass('device-offline');
});
1 Like

Thank you, that’s a very elegant solution for handling all the offline display state for the UI and I guess it will just self update the layout through css targeting changes.
On the cordova-plugin-network-information GitHub it says to attach the online / offline event listeners to document, does it make a difference if it’s in window or document? And should I be placing this inside the document deviceready listener?

So how would I force the native keyboard to close, or is that out of the scope of web apps?

you can use document instead of window
it can be outside of “deviceready”

if you want to close the keyboard
you can :

  • blur the input
    or
  • hide the input
    or
  • use keyboard-plugin then run =>
Keyboard.hide();
1 Like

Or just

document.activeElement.blur()
4 Likes