Question

I want that when i click on Update button then it should validate the user as required field, i added attribute e-required but not working.

Please see this fiddle: http://jsfiddle.net/NfPcH/669/

HTML:

<h4>Angular-xeditable Trigger manually (Bootstrap 3)</h4>
<div ng-app="app" ng-controller="Ctrl">
<span editable-text="user.name" e-form="textBtnForm" buttons="no" e-required />
{{ user.name || 'empty' }}
</span>
 <button class="btn btn-default" ng-click="(textBtnForm.$visible && save()) || textBtnForm.$show()" >
  {{textBtnForm.$visible | editOrUpdate}}
 </button>
</div>

Js Controller:

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

app.filter('editOrUpdate', function() {
return function(arg) {
    return (arg) ? 'Update' : 'Edit';
};
});

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

app.controller('Ctrl', function($scope) {
$scope.user = {
name: 'awesome user'
};
$scope.save = function(event){
    $scope.textBtnForm.$save();
    //save here your data
    //call the object that you passed ($scope.user)
    //get te specific value at ($scope.user.name)
    //alert($scope.user.name);
    return true;
};
});

Please help me to resolve this.

Thanks.

Was it helpful?

Solution

Please try as shown below.Good Luck ! :)

Html

<div ng-app="app" ng-controller="Ctrl">
  <span editable-text="user.name" e-form="textBtnForm" e-required>
    {{ user.name || 'empty' }}
  </span>
  <button class="btn btn-default" ng-click="textBtnForm.$show()" ng-hide="textBtnForm.$visible">
    edit
  </button>
</div>

JS

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

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

app.controller('Ctrl', function($scope) {
  $scope.user = {
    name: 'awesome user'
  };
});

Live Demo : JSFiddle

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top