Skip to content

Commit

Permalink
Add dynamic keyboard config in ngVirtualKeyboard directive
Browse files Browse the repository at this point in the history
  • Loading branch information
antonio-spinelli committed Jan 8, 2019
1 parent 809c07e commit 8045924
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/ng-virtual-keyboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,32 @@ angular.module('ng-virtual-keyboard', [])
return;
}

ngVirtualKeyboardService.attach(element, scope.config, function(e, kb, el) {
$timeout(function() {
ngModelCtrl.$setViewValue(element.value);
var createKeyboard = function(element, config) {
ngVirtualKeyboardService.attach(element, config, function(e, kb, el) {
$timeout(function() {
ngModelCtrl.$setViewValue(element.value);
});
});
});
};

scope.$on('$destroy', function() {
var keyboard = $(element).getkeyboard();
var destroyKeyboard = function(element) {
var keyboard = ngVirtualKeyboardService.getKeyboard(element);
if (keyboard) {
keyboard.destroy();
}
};

createKeyboard(element, scope.config);

scope.$watch('config', function (newConfig, oldValue) {
if (newConfig) {
destroyKeyboard(element);
createKeyboard(element, newConfig);
}
}, true);

scope.$on('$destroy', function() {
destroyKeyboard(element);
});
}
};
Expand Down

0 comments on commit 8045924

Please sign in to comment.