0

I have a form that gets completed on a webpage by the user, when the user submits the form, I bring up a bootstrap modal dialog, this dialog has an iframe in it that loads the form from the parent window calling a function in it like so:

//parent window
var formToSubmit;
function getForm(){
   return formToSubmit;
}

$("#submitButton").click(function(){
   //alterations to the elements in $("mainForm")

   formToSubmit = $("mainForm");
   $("#modalDialog").modal();
   //...
});

//modal iframe
var parentForm = parent.window.getForm();
$("#mainDiv").append(parentForm[0].outerHTML);
$("form").submit(function(){
   parent.window.closeModalWindow(); //not sure whether this will close AFTER the form is completely submitted yet

});

$("form").submit();

My problem is that I'm submitting these forms to microsoft sql server reporting services and it takes every input element as a parameter. I have no control over this.

So when the user clicks submit in the main form, I disable all the elements that must not be set as parameters, the thing is; as soon as I get the form from the parent window and append it to the modal iframe, it seems as all of those changes are lost, is there any way to preserve this?

4

1 回答 1

3

您的问题可能与表单上对 outerHTML 的调用有关。首先,outerHTML 的实现在不同的浏览器中是不同的,所以我会尽可能避免使用它。其次,outerHTML 不一定包含活动的 DOM 元素,而只是将其作为字符串转储。

因此,我建议在将表单传递给您的 IFRAME 之前对其进行深度克隆。

使用 jQuery(请参阅文档):

$("#mainDiv").append(parentForm.clone(true));

或纯 JavaScript(请参阅文档):

document.getElementByid('mainDiv').appendChild(parentForm[0].cloneNode(true));

我进行了一些测试来验证这一点,只要你克隆表单,你就会得到你期望的结果。


作为旁注,您为什么要在模式中复制表单?您是否将其重新创建为用户的“请审查”类型的东西?这似乎是一个奇怪的过程。我只问,因为也许有更好的方法来做你所要求的。无论如何,我给出的答案应该会有所帮助。

于 2013-07-17T14:32:14.567 回答