提交表单后,如何处理要忽略的表单/输入 [英] How can I manipulate a form / inputs to be ignored when a form is submitted
问题描述
我正在将ExpressionEngine和SafeCracker与Ajax一起使用(插件:jquery.form.js- http://jquery.malsup.com/form/).
据我所知,SafeCracker一次只能更新一个条目.但是,UI/UX必须显示列表.我已经按概念证明了按需输入表格的形式.也就是说,单击每个条目旁边的特定编辑链接,然后jquery的一个片段将创建一个表单并显示一个提交按钮.单击提交,该条目将更新.在单击更新"链接之前,输入不存在
如果可能的话,我宁愿做的是在重新绘制页面时创建每个条目的非表单和表单版本,并使用某种切换来显示一个或另一个.再次,可行.然后,当我单击编辑"链接时,我会将必要的属性添加到输入,以便将读取条目的表单元素,但将忽略其他条目的其他(显示:无)元素.我在想(大声)如果我添加attr("name",some-value)会起作用.也就是说,没有名称的输入将被忽略.
是的,我可以测试一下,我会的.但是,即使它可行,我也不确定这是否是最佳实践和/或是否有实现目标的更理想的方法.我在这里寻找验证和/或其他专业知识和意见.
先谢谢了.
只需将disabled
属性设置为输入,无论输入字段是什么,它们都会从 表单提交 中排除是hidden
或visible
.不同的jQuery方法(例如submit()
和serialize()
)遵循HTML 4的规范,并排除了表单的所有禁用控件.因此,一种方法是设置
$('your_input').prop('disabled', true);
或,
$('your_input').attr('disabled', 'disabled');
检查以下链接:
http://www.w3.org/TR/html401/interact/forms.html#successful-controls
此外,您可以使用通用的button
而不是submit
,这样您就可以处理其上的click事件,并且在该事件内您可以进行排除,验证,对值的操作以及您喜欢的任何操作. /p>
I'm using ExpressionEngine and SafeCracker along with Ajax (plugin: jquery.form.js - http://jquery.malsup.com/form/).
Best I can tell, SafeCracker will only allow for updating a single entry at a time. However, the UI / UX necessitates that a list be displayed. I've proof of concept'ed an entry by entry on-demand form. That is, click a particular edit link next to each entry and a snippet of jquery creates a form along with displaying a submit button. Click submit and that single entry updates. The inputs don't exist until the Update link is clicked
What I would prefer to do, if possible, is to create the non-form and form versions of each entry as the page is renbered and use some sort of toggle to display one or the other. Again, doable. Then, when I click the Edit link I'd add the necessary attributes to the input so that entry's form elements will be read but the other (display: none) elements for the other entries will be ignored. I'm thinking (out loud) that if I add the attr("name", some-value) that would work. That is, an input with no name will be ignored.
Yes, I can test this and I will. However, even if it works I'm not sure if it's a best practice and/or there's a more ideal way of accomplishing my ends. I'm here looking for validation and/or additional expertise and input.
Thanks in advance.
Just set disabled
property to inputs and they will excluded from Form submission, whatever input fields are hidden
or visible
. Different jQuery methods, like submit()
and serialize()
follow specification of HTML 4 and exclude all disabled controls of a forms. So one way is to set
$('your_input').prop('disabled', true);
or ,
$('your_input').attr('disabled', 'disabled');
Check following link:
http://www.w3.org/TR/html401/interact/forms.html#successful-controls
Also, you may use a general button
instead of a submit
, as result you can handle click event on it and within that event you can make exclusion, validation, manipulation on values and what ever you like.
这篇关于提交表单后,如何处理要忽略的表单/输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!