emporio emporio - 5 months ago 67
AngularJS Question

Use x-editable to make a different element editable on click

Using the x-editable dependency, I would like to make a different element editable when I click on an underlying image element.

<h4>Angular-xeditable Text (Bootstrap 3)</h4>
<div ng-app="app" ng-controller="Ctrl">
<h3 class="m-t-lg m-b-sm inline-block" id="line{{lineId}}" editable-text="headingLineContent.someText">{{ headingLineContent }}</h3><br>
<a href="" class="disabled"><i class="fa fa-pencil pencil m-l-sm" ng-click="">{{ myImage }}</i></a>
</div>


Here is the JS:

var app = angular.module("app", ["xeditable"]);

app.run(function(editableOptions) {
editableOptions.theme = 'bs3';
});

app.controller('Ctrl', function($scope) {
$scope.headingLineContent = 'Some Text';
$scope.myImage = 'MyImage.jpg';
});


And here is the fiddle: http://jsfiddle.net/emporio/h1zsw5nu/4/

So basically when I click the underlying element, the text above should become editable.

Answer

Read the "Trigger Manually" article from here: http://vitalets.github.io/angular-xeditable/#text-btn

Working fiddle: http://jsfiddle.net/koljada/h1zsw5nu/5/

<div ng-app="app" ng-controller="Ctrl">
  <p>
    <h3 class="m-t-lg m-b-sm inline-block" id="line{{lineId}}" editable-text="headingLineContent" e-form="textBtnForm">{{ headingLineContent }}</h3>
  </p>
  <p>
    <a href="" class="disabled" ng-click="textBtnForm.$show()" ng-hide="textBtnForm.$visible"><i class="fa fa-pencil pencil m-l-sm" ng-click="">{{ myImage }}</i></a>
  </p>
</div>