Last active
December 21, 2015 20:09
-
-
Save DavidFrahm/6359616 to your computer and use it in GitHub Desktop.
WIP - Trying to help form submission in iOS for ensuring dismissal of onscreen keyboard (Go button vs form button element). Note that this may not be needed in iOS 7.0+; Need to do more testing to be sure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('TouchSubmit', []) | |
.directive('touchSubmit', function () { | |
return function (scope, element, attr) { | |
log('touchSubmit()'); | |
// jQuery version: | |
// var textFields = $(element).children('input[type=text]'); | |
// $(element).submit(function() { | |
// log('touchSubmit() > form was submitted'); | |
// textFields.blur(); | |
// }); | |
// jqLite version: | |
var textFields = element.find('input'); | |
element.bind('submit', function() { | |
log('touchSubmit() > form was submitted'); | |
/* To dismiss onscreen keyboard */ | |
// In some cases, focus was needed before blur to dismiss onscreen keyboard | |
textFields[0].focus(); | |
textFields[0].blur(); | |
/* To ensure status messages are visible on small screens */ | |
$window.scrollTo(0, 0); | |
/* Trying to work with scrollable content (fixed navbar) | |
// var scrollable = angular.element('div.scrollable'); | |
var scrollable = document.querySelector('.scrollable'); | |
var ngScrollable = angular.element(scrollable); | |
log(scrollable[0]); | |
log(ngScrollable); | |
ngScrollable[0].scrollTo(0, 0); | |
*/ | |
}); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form name="LoginForm" ng-submit="submit(user);" touch-submit> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment