漂亮的表格导致清晰的表格问题
由于某种原因,在我的表单上,当它清除字段时,它会将下拉列表的值重置为“”,但它不显示选项的实际文本?有什么想法吗?
$(':input','#templatesForm')
.not(':submit, :button, :hidden, :reset')
.val('');
编辑:
<select size="1" name="status" id="status">
<option value="">- Select -</option>
<?php
echo $statuses;
?>
</select>
编辑2:
我不知道是什么导致了这个问题,无论是好的表单还是jQuery表单验证插件还是什么,因为单击重置按钮后我知道使用此代码:
$("#reset").click(function() {
validator.resetForm();
});
我有一些下拉菜单和表单重置它会重置所有表单字段的值,甚至下拉列表的值,但下拉列表的文本仍与用户上次更改的内容相同。有谁知道使选择刷新以使其初始选项成为默认选项的解决方案?
编辑3:
来自任何人的任何想法,因为我已经被这个问题困扰了几天了。
编辑4:
希望我能找到至少有一个想法的人!
编辑5:
这是一个js小提琴,它可以完成我正在谈论的事情。它将下拉列表的值重置为0,但不会将文本选项更改回默认值 - Select -
For some reason on my form when it clears the fields it resets the value of the dropdowns to '' but it does not show the actual text of the option? Any ideas why?
$(':input','#templatesForm')
.not(':submit, :button, :hidden, :reset')
.val('');
EDIT:
<select size="1" name="status" id="status">
<option value="">- Select -</option>
<?php
echo $statuses;
?>
</select>
Edit 2:
I don't know what is causing this issue whether it be nice forms or the jQuery form validation plugin or what because with the reset button clicked I know use this code:
$("#reset").click(function() {
validator.resetForm();
});
I have a few dropdowns and with the form reset it resets the values of all form fields even the dropdown however the text of the dropdown remains the same as the user's last change. Does anyone know and solution to make the select refresh so that its initial option is the default option?
Edit 3:
Any ideas from anyone because I've been stumped on this for a few days now.
Edit 4:
Hoping I get someone that has atleast one idea!
Edit 5:
Here's a js fiddle that does what I"m talking about. It resets the value of the dropdown to 0 but does not change the text option back to the default of - Select -
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,我删除了您的小提琴所有附加脚本(验证和模板):
http://jsfiddle。 net/Jacek_FH/EwpXp/5/
接下来,我修补了重置功能以与 Niceforms select 一起使用:
http://jsfiddle.net/Jacek_FH/EwpXp/7/
Niceforms 如何工作?
这个想法很简单:由于普通输入字段(包括单选按钮、复选框、文本区域等)只能在很小程度上设置样式,因此必须隐藏它们,并将其视觉外观替换为类似的工作、新的、完全可定制的结构。从理论上讲,这听起来并不复杂。但从理论到实践还有很长的路要走。
如何处理选择
当触发表单重置时,所有 html 输入都会重置,但 Niceforms 会使用 div 复制选择。因此,我已将选项中的值复制到 Niceforms div 中(重置后)。我的代码:
编辑
考虑后,还有其他方法-您可以重新加载Niceforms。但它是有代价的——形式闪烁
First, I've stripped Your fiddle of all additional scripts (validate and template) :
http://jsfiddle.net/Jacek_FH/EwpXp/5/
next, I've patched reset function to work with niceforms select:
http://jsfiddle.net/Jacek_FH/EwpXp/7/
How Does Niceforms Work?
The idea is simple: since normal input fields (including radio buttons, checkboxes, textareas, etc) can only be styled to a small degree, they have to be hidden and their visual appearance replaced with similar working, new, fully customizable constructs. In theory, that doesn't sound really complicated. But from theory to practice there is a long way.
How is select handled
When reset on form is triggered, all html inputs are reset, but Niceforms duplicate select with divs. So I've copied value from option into Niceforms div (after reset). My code:
edit
after considering, there is also other way - you could reload Niceforms. But it has a price - form blinks
您正在重置值,但没有更改选择,因此显然选择不会自行更改。
考虑这样的事情:
You are resetting the values, but not changing the selection, so obvoiusly the selection won't change on its own.
Consider something like: