JSFiddle - React, Tailwind, and code Playground

by jtowell

HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.js"></script>
<script src="https://raw.github.com/angular-ui/angular-ui/master/build/angular-ui.js"></script>
<div ng-app="focus" ng-controller="FocusCtrl" ng-cloak class="ng-cloak">
<ul class="unstyled">
    <li>
       <span ng-hide="formValue1.edit" ng-click="formValue1.edit=true">{{formValue1.stringValue}}</span>             
        <select focus-on="formValue1.edit" ng-show="formValue1.edit" ui-event="{ blur : 'formValue1.edit=false' }">
          <option value="one">one</option> 
          <option value="two">two</option> 
        </select>        
   </li>
   <li>
        <span  ng-hide="formValue2.edit" ng-click="formValue2.edit=true">{{formValue2.stringValue}}</span>                
        <select focus-on="formValue2.edit" ng-show="formValue2.edit" ui-event="{ blur : 'formValue2.edit=false' }">
          <option value="one">one</option> 
          <option value="two">two</option> 
        </select>        
    </li>
</ul>
</div>

JavaScript

angular.module('focus', ['ui', 'focusOn']);

function FocusCtrl($scope) {
    $scope.formValue1 = {stringValue:'Form Value1', edit:false};
    $scope.formValue2 = {stringValue:'Form Value2', edit:false};
}
angular.module('focusOn', []).directive('focusOn', function() {
    return {
        restrict: 'A',
        link:function (scope, element, attrs) {
            scope.$watch(attrs.focusOn, function(value){
                if(attrs.focusOn) {
                    window.setTimeout(function(){
                        element.focus();
                    },10);
                }
            }, true);
        }
    };
});