How to create form editable using "Popover"

0

How do I change the code below to work with the% class of Angular-xeditable% Demo .

var app = angular.module("app", ["xeditable"])
.run(function(editableOptions) {
  editableOptions.theme = 'bs3';
})
.controller('Ctrl', function($scope) {
  $scope.targetIndex = -1;
  
  $scope.toggle = function(index){

    // Se o targetIndex atual for o mesmo do selecionado, então apague.
    // Caso contrário, salve o índice selecionado em targetIndex.

    $scope.targetIndex = ($scope.targetIndex == index ? null : index);
  }
  
  $scope.users = [
  {    name: 'awesome user I'  }, 
  {    name: 'awesome user II'  }, 
  ];
});
div[ng-app] { margin: 50px; }
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-sanitize.min.js"></script>
<script src="https://vitalets.github.io/angular-xeditable/dist/js/xeditable.js"></script><h4>Angular-xeditableText(Bootstrap3)</h4><formng-app="app" ng-controller="Ctrl" editable-form name="formulario">
  
  <div ng-repeat="user in users track by $index">
  <a href="#" ng-click="toggle($index)" ng-show="!(targetIndex == $index)" editable-text="user.name">{{ user.name || 'empty' }}</a>
  <input type='text' ng-model="user.name" ng-show="targetIndex == $index"/>
    <div class="buttons">
      <!-- buttons to submit / cancel form -->
      <span ng-show="targetIndex == $index">
        <br/>
        <button type="submit" class="btn btn-primary" ng-disabled="formulario.$waiting" ng-click="toggle($index)">
          Save
        </button>
        <button type="button" class="btn btn-default" ng-disabled="formulario.$waiting" ng-click="toggle($index)">
          Cancel
        </button>
      </span>
    </div>
  <br />
  </div>
</form>
    
asked by anonymous 02.07.2017 / 21:53

1 answer

0

You have been missing two more dependencies: boostrap css and xeditable css , also removed form , because api does all the work dynamically.

var app = angular.module("app", ["xeditable"])
.run(function(editableOptions) {
  editableOptions.theme = 'bs3';
})
.controller('Ctrl', function($scope) {

  //Comentei esse trecho pois ele estava ocultando o botão
	
  //$scope.targetIndex = -1;
  
  //$scope.toggle = function(index){

    // Se o targetIndex atual for o mesmo do selecionado, então apague.
    // Caso contrário, salve o índice selecionado em targetIndex.

    //$scope.targetIndex = ($scope.targetIndex == index ? null : index);
  //}
  
  $scope.users = [
  {    name: 'awesome user I'  }, 
  {    name: 'awesome user II'  }, 
  ];
});
div[ng-app] { margin: 50px; }
.pop {
  margin:0;
  margin-top: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.popover-wrapper:active{
  color: black;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script><scriptsrc="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-sanitize.min.js"></script>
<script src="https://vitalets.github.io/angular-xeditable/dist/js/xeditable.js"></script><linkhref="https://netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://vitalets.github.io/angular-xeditable/dist/css/xeditable.css" rel="stylesheet"/>



<body ng-app="app" ng-controller="Ctrl">
<div ng-repeat="user in users track by $index" class="pop">
  <div class="popover-wrapper">
    <a href="#" ng-click="toggle($index)" ng-show="!(targetIndex == $index)" editable-text="user.name">{{ user.name || 'empty' }}</a>
  </div>
  </div>
</body>
    
03.08.2017 / 22:35