[英]I want to avoid a file too large error when I clear the screen
I have a page with a file upload option using 我有一个使用文件上传选项的页面
<input type="file" name="fileUpload" />
and it works fine. 而且效果很好。
I also have a Clear button on the screen which calls a method to reset all of the page fields to their default values. 我在屏幕上还有一个“ 清除”按钮,该按钮调用一种方法来将所有页面字段重置为其默认值。
I use @SkipValidation
with the clear()
method so you don't get error messages if you clear a page with invalid data. 我将
@SkipValidation
与clear()
方法一起使用,因此,如果清除包含无效数据的页面,则不会收到错误消息。
My problem is: 我的问题是:
if I click to upload a file which is too large and then click the Clear button, I get the
"File too large"
message , because that is generated by the default-stack (at least that is my understanding) and not by my validation code.如果我单击上传一个太大的文件,然后单击“ 清除”按钮,则会收到
"File too large"
消息 ,因为该消息是由默认堆栈(至少是我的理解)而不是由我的验证生成的码。
I use document.getElementById('commentAction').reset();
我使用
document.getElementById('commentAction').reset();
in the method but that doesn't help. 在方法中,但这无济于事。
How can I reset the page without any error message ? 如何重置页面而没有任何错误消息?
UDATE Based on the suggestions I received I am using the following jquery. UDATE根据我收到的建议,我正在使用以下jquery。
function clearForm()
{
$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');
$(':checkbox, :radio').prop('checked', false);
}
along with the following struts2 for the Clear button 以及用于清除按钮的以下struts2
<s:submit key="button.clear" cssClass="submit" onclick="clearDirtyFlag(); clearForm(); return false" tabindex="18"/>
It now clears the input fields without leaving the page but I have a list on the page which is generated by the following struts2 code 现在,它清除输入字段而不离开页面,但是页面上有一个由以下struts2代码生成的列表
<s:iterator value="commentViewList" >
<div class="row rowaltcolor">
<div>
<s:url var="commentLink" action="commentAction" method="getCommentDetails">
<s:param name="commentId"><s:property value="commentInfo.commentId"/></s:param>
</s:url>
<div class="col-sm-1 col-xs-12 text-left"><s:a href="%{commentLink}" tabindex="18"><s:property value="commentTypeCode"/></s:a></div>
<div class="col-sm-2 col-xs-12 text-left"><s:property value="commentInfo.name"/></div>
<div class="col-sm-2 col-xs-12 text-left"><s:property value="commentInfo.organization"/></div>
</div>
</s:iterator>
This list does not get cleared because it isn't a field in the generated html. 此列表不会清除,因为它不是生成的html中的字段。 The list values are hardcoded in the html when I look at the source html.
当我查看源html时,列表值被硬编码在html中。 Can I clear the list on the client side or do I need to do that on the server side and re-display the page?
我可以在客户端清除列表还是在服务器端清除列表并重新显示页面? Thanks!
谢谢!
For anyone who is googling I thought I should put what solved the problem for me in an answer. 对于那些正在使用谷歌搜索功能的人,我认为我应该把解决问题的方法放在我的答案中。 Using
运用
function clearForm()
{
$(':input').not(':button, :submit, :reset, :hidden, :checkbox, :radio').val('');
$(':checkbox, :radio').prop('checked', false);
}
cleared all of the input fields (including hidden fields) without going to the action. 清除所有输入字段(包括隐藏字段),而无需执行操作。 I still used a
<s:submit>
tag but I used return false to keep the page from being submitted as follows. 我仍然使用
<s:submit>
标记,但是我使用return false来阻止页面提交,如下所示。
<s:submit key="button.clear" cssClass="submit"
onclick="clearForm(); clearDirtyFlag(); return false" tabindex="18" />
For my page that didn't work because I had a list generated by struts on the page I needed to clear so I had to go ahead and call my action and render the page again. 对于我的页面不起作用,因为我需要清除页面上由struts生成的列表,因此我必须继续调用我的操作并再次呈现该页面。 So my final submit code was
所以我最后的提交代码是
<s:submit method="reset" key="button.clear" cssClass="submit"
onclick="clearForm(); clearDirtyFlag();" tabindex="18" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.