// Declare app level module which depends on filters, and services
-angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives', '$strap.directives' ]).
+angular.module('myApp', ['myApp.filters', 'myApp.services', 'myApp.directives' ]).
config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/registration/:registrationId', {templateUrl: 'partials/registration.html', controller: RegistrationCtrl});
$routeProvider.when('/confirmation/:registrationId', {templateUrl: 'partials/confirmation.html', controller: RegistrationCtrl});
var my_type = attrs['type'] || 'text';
var html = '<div class="'+my_class+'">'
+'<label for="'+attrs.ngModel+'">' + attrs.placeholder + '</label>'
- +'<input type="'+my_type+'" name="'+attrs.ngModel+'" ng-model="' + attrs.ngModel + '" ng-required="' + attrs.ngRequired + '" placeholder="' + attrs.placeholder + '" class="'+my_class+'" />'
- +'</div>'
+ +'<input type="'+my_type+'" name="'+attrs.ngModel+'" ng-model="' + attrs.ngModel + '"'
+ +' placeholder="'+attrs.placeholder+'" class="'+my_class+'"'
;
+ if ( attrs.ngRequired ) html += ' ng-required="' + attrs.ngRequired + '"';
+ if ( attrs.bsTypeahead ) html += ' bs-typeahead="'+attrs.bsTypeahead+'"';
+ if ( attrs.dataItems ) html += ' data-items="'+attrs.dataItems+'"'; // for typeahead
+ html += '/></div>';
element.replaceWith(html);
}
};
- });
+ })
+.directive('bsTypeahead', ['$parse', function($parse) {
+ 'use strict';
+
+ return {
+ restrict: 'A',
+ require: '?ngModel',
+ link: function postLink(scope, element, attr, controller) {
+
+ var getter = $parse(attr.bsTypeahead),
+ setter = getter.assign,
+ value = getter(scope);
+
+ // Watch bsTypeahead for changes
+ scope.$watch(attr.bsTypeahead, function(newValue, oldValue) {
+ if(newValue !== oldValue) {
+ value = newValue;
+ }
+ });
+
+ element.attr('data-provide', 'typeahead');
+ element.typeahead({
+ source: function(query) { return value; },
+ items: attr.items,
+ updater: function(value) {
+ // If we have a controller (i.e. ngModelController) then wire it up
+ if(controller) {
+ scope.$apply(function () {
+ controller.$setViewValue(value);
+ });
+ }
+ return value;
+ }
+ });
+
+ // add entered element into typeahead array for other fields
+ element.bind('blur', function() {
+ var new_value = element.val();
+ if ( new_value.length > 1 && $.inArray( new_value, value ) === -1 ) { // IE doesn't have .indexOf
+ scope.$apply( function() {
+ value.unshift( element.val() );
+ });
+ }
+ });
+
+ }
+ };
+}])
+;