admin管理员组文章数量:1314480
I have a form within which i have used x-editable
plugin for editing a text-field. But i am getting the following script error. Can anyone please tell me some solution for this
Form with editable elements should have `editable-form` attribute. <span editable-text="user.name" e-form="textBtnForm" class="ng-scope ng-binding editable">
Working Demo
html
<div ng-app='myApp' ng-controller="ArrayController">
<form action="#" >
<span editable-text="user.name" e-form="textBtnForm">
{{ user.name || 'empty' }}
</span>
<button class="btn btn-default" ng-click="textBtnForm.$show()" ng-hide="textBtnForm.$visible">edit
</button>
</form>
</div>
script
var app = angular.module('myApp', ["xeditable"]);
app.controller('ArrayController', function ($scope) {
$scope.test = "manu";
$scope.user = {
name: 'awesome user'
};
});
I have a form within which i have used x-editable
plugin for editing a text-field. But i am getting the following script error. Can anyone please tell me some solution for this
Form with editable elements should have `editable-form` attribute. <span editable-text="user.name" e-form="textBtnForm" class="ng-scope ng-binding editable">
Working Demo
html
<div ng-app='myApp' ng-controller="ArrayController">
<form action="#" >
<span editable-text="user.name" e-form="textBtnForm">
{{ user.name || 'empty' }}
</span>
<button class="btn btn-default" ng-click="textBtnForm.$show()" ng-hide="textBtnForm.$visible">edit
</button>
</form>
</div>
script
var app = angular.module('myApp', ["xeditable"]);
app.controller('ArrayController', function ($scope) {
$scope.test = "manu";
$scope.user = {
name: 'awesome user'
};
});
Share
Improve this question
edited Jul 28, 2014 at 13:34
Huangism
16.4k7 gold badges50 silver badges75 bronze badges
asked Jul 28, 2014 at 13:31
Alex ManAlex Man
4,88619 gold badges105 silver badges188 bronze badges
3 Answers
Reset to default 4There are a couple things to do:
- add the
editable-form
attribute to the form as the error suggest. - remove the
e-form="textBtnForm"
, it's not required for your requirement. - instead, set the
textBtnForm
as a name of the form. - add
type="button"
to the edit button, otherwise it doesn't work (don't know why ..). - I've also add save and cancel button when editing for the sake of pleteness.
The result would look like this:
<form editable-form name="textBtnForm" action="#">
<span editable-text="user.name">
{{ user.name || 'empty' }}
</span>
<button type="button" class="btn btn-default" ng-click="textBtnForm.$show()" ng-hide="textBtnForm.$visible">
edit
</button>
<span ng-show="textBtnForm.$visible">
<button type="submit" class="btn btn-primary" ng-disabled="textBtnForm.$waiting">
Save
</button>
<button type="button" class="btn btn-default" ng-disabled="textBtnForm.$waiting" ng-click="textBtnForm.$cancel()">
Cancel
</button>
</span>
</form>
JSFiddle: http://jsfiddle/5TZX5/1/
Hope this helps.
If there is just a single element you want to edit, you can remove the form, which will make it work.
Or you must add ng-click="$form.$show()"
to the span
element as described here.
the previous approach is partial correct and can be applied only if use a single input in that form. Also if you try to add more elements, then will not work correct. So the right solution that i have is to use ng-form with editable-form directive as block for each form element (input) that you want apply the xedit plugin, and of course remove editable-form from main form.
the sample based by your code is below:
<div ng-app='myApp' ng-controller="ArrayController">
<form action="#" >
<div ng-form editable-form name="textBtnForm">
<span editable-text="user.name" ng-click="textBtnForm.$show()">{{user.name||'empty'}}</span>
<span ng-show="textBtnForm.$visible">
<button type="button" class="btn btn-primary" ng-disabled="textBtnForm.$waiting" ng-click="textBtnForm.$submit()"> Save</button>
<button type="button" class="btn btn-default" ng-disabled="textBtnForm.$waiting" ng-click="textBtnForm.$cancel()">cancel</button>
</span>
</div>
<hr>second form element<hr>
<div ng-form editable-form name="textBtnForm2">
<span editable-text="user.phone" ng-click="textBtnForm2.$show()">{{ user.phone || 'empty' }}</span>
<span ng-show="textBtnForm2.$visible">
<button type="button" ng-disabled="textBtnForm2.$waiting" ng-click="textBtnForm2.$submit()">Save</button>
<button type="button" class="btn btn-default" ng-disabled="textBtnForm2.$waiting" ng-click="textBtnForm2.$cancel()"> Cancel</button>
</span>
</div>
</form>
</div>
本文标签: javascriptForm with editable elements should have editableform attributeStack Overflow
版权声明:本文标题:javascript - Form with editable elements should have `editable-form` attribute - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741968848a2407711.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论