El formulario BeginFormSitefinity desaparece después de enviar
Cuando uso elBeginFormSitefinity
ayudante, el formulario desaparece después de enviarlo, y luego se realiza la devolución.
El comportamiento esperado sería solo la devolución de datos a realizar. Fui al navegador e investigué y descubrí que cuando usasBeginFormSitefinity
se agrega un script adicional a su html.
Ese script básicamente crea un nuevo formulario con display = none. Y agrega su formulario al formulario "invisible", y así su formulario desaparece después de enviarlo.
Estoy usando Sitefinity 8.1, y me gustaría saber si hay alguna forma de evitar esto.
Este es el script agregado (no tengo control sobre él):
<script type="text/javascript">
(function () {
var container = document.getElementById("myForm2");
if (container === null)
return;
var inputs = container.querySelectorAll("input");
var allInputs = document.forms["aspnetForm"].querySelectorAll('input');
for (var i = 0; i < allInputs.length; i++) {
allInputs[i].addEventListener("invalid", function(event) {
if (Array.indexOf(inputs, document.activeElement) >= 0 && Array.indexOf(inputs, event.target) < 0)
event.preventDefault();
}, true);
}
var submitClick = function () {
var isValid = true;
for (var i = 0; i < inputs.length; i++) {
if (typeof inputs[i].willValidate !== "undefined" && inputs[i].willValidate)
isValid = inputs[i].validity.valid && isValid;
if (typeof jQuery !== "undefined" && typeof jQuery.validator !== "undefined")
isValid = jQuery(inputs[i]).valid() && isValid;
}
if (isValid) {
var form = document.createElement("form");
form.style.display = "none";
form.setAttribute("action", "/order-calendar/Search");
form.setAttribute("method", "POST");
form.setAttribute("enctype", document.forms["aspnetForm"].getAttribute("enctype"));
form.setAttribute("encoding", document.forms["aspnetForm"].getAttribute("encoding"));
form.appendChild(container);
document.body.appendChild(form);
// We prevent kendo upload widget from submitting empty inputs.
var kInputs = container.querySelectorAll(".k-upload input[type='file']");
for(var i = 0; i < kInputs.length; i++) {
var kInput = kInputs[i];
if (!kInput.value) {
// Prevent submitting an empty input
kInput.setAttribute("disabled", "disabled");
window.setTimeout(function() {
kInput.removeAttribute("disabled");
}, 0);
}
}
form.submit();
return false;
}
};
var handleFormSubmitElements = function (elementName) {
var allSubmitElements = container.getElementsByTagName(elementName);
var elementCount = allSubmitElements.length;
while(elementCount) {
typeAttr = allSubmitElements[elementCount - 1].getAttribute("type");
if(typeAttr == "submit") {
allSubmitElements[elementCount - 1].onclick = submitClick;
}
elementCount--;
}
};
handleFormSubmitElements("input");
handleFormSubmitElements("button");
})();
</script>
Este es mi formulario (sus valores se leen automáticamente, por eso onkeydown devuelve falso):
@using (Html.BeginFormSitefinity("Search", "myForm2"))
{
<div id="main_content" style="max-width: 600px; max-height:700px;float:left;overflow: hidden;">
<table>
<tr><td colspan="2" style="text-align:center;">@Html.Label("City")</td></tr>
<tr>
<td>@Html.Label("Code") </td>
<td>
@Html.Kendo().TextBoxFor(x => x.Code).HtmlAttributes(new { onkeydown = "return false", style = "color: green; width:100%;", id = "Code" })
</td>
</tr>
<tr>
<td>@Html.Label("City Code") </td>
<td>
@Html.Kendo().TextBoxFor(x => x.CityCode).HtmlAttributes(new { onkeydown = "return false", style = "color: green; width:100%;", id = "CityCode" })
</td>
</tr>
</table>
<input type="submit" class="btn btn-success" value="submit">
}
Esto es lo que sucede visualmente: