I am using angular-xeditable to edit elements within a form. I would like to have all the elements in "editable" mode at all times, e.g. no "edit" button needs to be pushed before the user starts editing.
我正在使用angular-xeditable来编辑表单中的元素。我希望所有元素始终处于“可编辑”模式,例如在用户开始编辑之前,不需要按下“编辑”按钮。
I have been trying to use the $show() in my controller to enable the elements in the form, however it seems like the elements goes into viewing state again for example when using "onaftersave" when trying to save the values etc.
我一直试图在我的控制器中使用$ show()来启用表单中的元素,但是看起来元素再次进入查看状态,例如在尝试保存值时使用“onaftersave”等。
How do I do in order to always be in edit mode where the user never needs to enable editing in order to start editing the values?
如何始终处于编辑模式,用户永远不需要启用编辑才能开始编辑值?
4 个解决方案
#1
7
Possibly try adding shown=true
in your html:
可能尝试在你的html中添加shown = true:
<form editable-form shown="true">
#2
5
I had this same problem. Even when trying to $show() the form again at the end of my onaftersave function it still wouldn't work. I suspect the visibility is being hidden after the onaftersave function runs but I didn't actually check if that's the case. Here's how I got around it:
我有同样的问题。即使在我的onaftersave函数结束时再次尝试$ show()表单时,它仍然无效。我怀疑在onaftersave函数运行后隐藏了可见性,但我实际上没有检查是否是这种情况。这是我如何解决它:
$scope.$watch('yourFormName.$visible', function() {
$scope.yourFormName.$show();
});
Now whenever the form visibility changes to hidden, it will just show it again regardless of when it changed.
现在,只要表单可见性更改为隐藏,它就会再次显示它,无论它何时更改。
#3
1
If your form is already open, and you just want to keep it open after submitting, you can do this:
如果您的表单已经打开,并且您只想在提交后将其保持打开状态,则可以执行以下操作:
<form editable-form name="MyForm" onbeforesave="saveMyData()" onaftersave="keepFormOpen()">
and the function keepFormOpen() would look something like this:
函数keepFormOpen()看起来像这样:
$scope.keepFormOpen = function() {
return "fake error message";
}
What this does is essentially gives the form a fake error message after you have already saved your data. This fake error message will interrupt the forms closing process, but since it was called after you already saved your data, it won't affect the previous submit.
这样做本质上是在您保存数据后给表单一个假的错误消息。这个假的错误消息将中断表单关闭过程,但由于它是在您保存数据后调用的,因此不会影响以前的提交。
#4
0
To really keep open the form we can do the following:
要真正保持打开表单,我们可以执行以下操作:
<form editable-form name="MyForm" onbeforesave="saveMyData()" onhide="MyForm.$show()">
#1
7
Possibly try adding shown=true
in your html:
可能尝试在你的html中添加shown = true:
<form editable-form shown="true">
#2
5
I had this same problem. Even when trying to $show() the form again at the end of my onaftersave function it still wouldn't work. I suspect the visibility is being hidden after the onaftersave function runs but I didn't actually check if that's the case. Here's how I got around it:
我有同样的问题。即使在我的onaftersave函数结束时再次尝试$ show()表单时,它仍然无效。我怀疑在onaftersave函数运行后隐藏了可见性,但我实际上没有检查是否是这种情况。这是我如何解决它:
$scope.$watch('yourFormName.$visible', function() {
$scope.yourFormName.$show();
});
Now whenever the form visibility changes to hidden, it will just show it again regardless of when it changed.
现在,只要表单可见性更改为隐藏,它就会再次显示它,无论它何时更改。
#3
1
If your form is already open, and you just want to keep it open after submitting, you can do this:
如果您的表单已经打开,并且您只想在提交后将其保持打开状态,则可以执行以下操作:
<form editable-form name="MyForm" onbeforesave="saveMyData()" onaftersave="keepFormOpen()">
and the function keepFormOpen() would look something like this:
函数keepFormOpen()看起来像这样:
$scope.keepFormOpen = function() {
return "fake error message";
}
What this does is essentially gives the form a fake error message after you have already saved your data. This fake error message will interrupt the forms closing process, but since it was called after you already saved your data, it won't affect the previous submit.
这样做本质上是在您保存数据后给表单一个假的错误消息。这个假的错误消息将中断表单关闭过程,但由于它是在您保存数据后调用的,因此不会影响以前的提交。
#4
0
To really keep open the form we can do the following:
要真正保持打开表单,我们可以执行以下操作:
<form editable-form name="MyForm" onbeforesave="saveMyData()" onhide="MyForm.$show()">