focus on first element in form when showing

This commit is contained in:
Henry Oswald 2014-06-16 16:22:45 +01:00
parent 7355a912b6
commit f18172258e
2 changed files with 8 additions and 1 deletions

View file

@ -120,7 +120,7 @@ block content
div(ng-show="formVisable")
form(enctype='multipart/form-data', method='post')
.input
input(type='text', name='first_name', ng-model="userInfoForm.first_name", ng-blur="sendUpdate()", placeholder="First Name")
input(type='text', name='first_name', ng-model="userInfoForm.first_name", ng-blur="sendUpdate()", placeholder="First Name", focus-input="formVisable")
.input
input(type='text', name='last_name', ng-model="userInfoForm.last_name", ng-blur="sendUpdate()", placeholder='Last Name')
.input#institution_auto_complete

View file

@ -5,6 +5,13 @@ define ["libs/algolia", "libs/angular", "libs/angular-autocomplete/angular-autoc
app.factory "Institutions", ->
new AlgoliaSearch("SK53GL4JLY", "75dc5e65794cd47eb7f725e6bb5075be").initIndex("institutions")
app.directive "focusInput", ($timeout) ->
return (scope, element, attr) ->
scope.$watch attr.focusInput, (value) ->
if value
$timeout ->
element.select()
app.controller "UpdateForm", ($scope, $http, Institutions)->
$scope.institutions = []
$scope.formVisable = false