如何自定义 data: :confirm 弹出窗口以提示输入,该输入将附加到请求参数中?
How can I customize the data: :confirm popup to prompt for an input, that will be appended to the request params?
我的应用程序中的许多地方,提交表单和访问 post-链接都要求用户说明他们决定这样做的原因(comments/reasoning 用于跟踪谁做了内部发生了什么变化)。
现在出于这个原因,我希望能够更改 data: {confirm: "Are you sure you want to submit this form?"}
的行为以提示输入而不是仅仅回答 yes/cancel。我希望该框显示一个输入字段,然后将其内容附加到请求参数,以便我可以从控制器存储它。
我该怎么做?
您可以使用提示:
var test = prompt("Enter your name:");
alert("Hi " + test + "!");
你能试试像 bootstrap 模态这样的模态服务吗,或者只是构建你自己的指令。有一些有用的信息 here。基本上,无论您将 ng-click 绑定到什么功能,都会首先调用 $modalService
,一旦用户 confirms/denies,$modalService 就会调用 func.success
或 func.error
使用伪提交按钮触发提示对话框。
当提示填满后,复制表单隐藏输入的值intu,然后触发表单提交事件。
这是工作示例:
HTML:
<form id="myForm">
<input type="checkbox" name="checkbox" checked />
<input id="myVisibleInput" name="visibleinput" type="text" />
<input id="myHiddenInput" name="hiddeninput" type="text" />
<button id="fakesubmit" type="button">Submit</button>
</form>
jQuery:
$('#fakesubmit').on('click', function() {
var answer = prompt('Why?');
if (answer != null) {
$('#myHiddenInput').val(answer);
$('#myForm').submit();
}
});
$("#myForm").on("submit", function(event) {
console.log($(this).serialize());
});
CSS:
#myHiddenInput {
display: none;
}
我的应用程序中的许多地方,提交表单和访问 post-链接都要求用户说明他们决定这样做的原因(comments/reasoning 用于跟踪谁做了内部发生了什么变化)。
现在出于这个原因,我希望能够更改 data: {confirm: "Are you sure you want to submit this form?"}
的行为以提示输入而不是仅仅回答 yes/cancel。我希望该框显示一个输入字段,然后将其内容附加到请求参数,以便我可以从控制器存储它。
我该怎么做?
您可以使用提示:
var test = prompt("Enter your name:");
alert("Hi " + test + "!");
你能试试像 bootstrap 模态这样的模态服务吗,或者只是构建你自己的指令。有一些有用的信息 here。基本上,无论您将 ng-click 绑定到什么功能,都会首先调用 $modalService
,一旦用户 confirms/denies,$modalService 就会调用 func.success
或 func.error
使用伪提交按钮触发提示对话框。 当提示填满后,复制表单隐藏输入的值intu,然后触发表单提交事件。 这是工作示例:
HTML:
<form id="myForm">
<input type="checkbox" name="checkbox" checked />
<input id="myVisibleInput" name="visibleinput" type="text" />
<input id="myHiddenInput" name="hiddeninput" type="text" />
<button id="fakesubmit" type="button">Submit</button>
</form>
jQuery:
$('#fakesubmit').on('click', function() {
var answer = prompt('Why?');
if (answer != null) {
$('#myHiddenInput').val(answer);
$('#myForm').submit();
}
});
$("#myForm").on("submit", function(event) {
console.log($(this).serialize());
});
CSS:
#myHiddenInput {
display: none;
}