具有输入类型文件字段的语义UI重置表单
Semantic UI reset form with input type file field
我使用的是语义UI,它总体上非常好。我遇到了一些不稳定的问题,我有一个表单,里面有输入类型文件字段。现在,当我调用$("form").form("reset")
时,我遇到了以下错误消息。
Uncaught InvalidStateError: Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
这不应该是一个简单的重置吗?我在这里错过了什么。对于这样的操作,我更喜欢使用语义UI提供的功能,但到目前为止我还是被卡住了。
如果没有完整的示例,我不确定您的错误来自哪里,但是form('reset')
在<input type='file'>
中使用语义ui 2.1.8正确工作。请参阅以下示例:
$(document).ready(function(){
// initialize the form an fields
$('.ui.form')
.form({
fields: {
fileInput:{
identifier: 'name',
rules: [
{
type : 'empty'
}
]
}
}
});
});
function myOwnReset(){
$('.ui.form').form('reset');
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.8/semantic.min.js"></script>
<form class="ui form segment">
<div class="field">
<label>File</label>
<input type="file" name="fileInput"></input>
</div>
<div class="ui blue submit button">Submit</div>
<div class="ui reset button">Reset</div>
<div class="ui clear button">Clear</div>
</form>
<input type="button" onClick="myOwnReset();" value="force form('reset')"></input>
在本例中,我使用了<div class="ui reset button">Reset</div>
中添加的默认Reset
功能。无论如何,我添加了一个按钮来查看强制form('reset')
是否按预期工作。
希望有帮助,
这将清除表单
<div class="ui clear button" onclick="$('.ui.form').form('clear')">Clear</div>
相关文章:
- 语义ui如何使用javascript启用或禁用下拉列表
- 语义ui表单验证:图像url
- 语义UI中格式化的工具提示
- Meteor.js可以'找不到语义:ui包
- Template.subscriptionReady和语义UI Accordion模块
- 语义UI下拉选项数据属性
- 语义UI动态下拉菜单重新初始化问题
- 基于语义UI的页面在Tide SDK中无法正常工作
- 语义 UI 手风琴获取打开事件中打开的项目的索引
- javascript+语义ui:垂直菜单与项目之间的对话框,如何
- 如何使用语义ui模态
- 具有输入类型文件字段的语义UI重置表单
- 设置值时,语义UI下拉列表滞后于整个UI
- 语义UI粘性模块不工作
- 语义 UI 模式未定义
- 如何在语义UI中使用模态自动获取不同的图像
- 语义 UI 下拉列表所选文本和值似乎很奇怪
- 语义 UI - 下拉远程内容 - 额外数据
- 语义 UI:访问搜索组件选定项
- 语义 UI 模态导致我的元素在关闭后从 DOM 中消失