如何冻结或禁用更新输入表单
我想知道我是否可以冻结或禁用整个更新表单?我有一个输入 h:form ,其中有一个复选框。当用户选中该框时,我想冻结或禁用整个表单,以便禁止用户更改输入。
谢谢,我正在使用 JSF、Spring Web Flow、Facelets 和 Trinidad。
I wonder if it is possible for me to freeze or disable the entire update form? I have an input h:form with a check box in it. when users check the box, I would like to freeze or disable the entire form so that disallow users from changing inputs.
Thanks, and I am using JSF, Spring Web Flow, Facelets, and Trinidad.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当用户选中复选框时,您可能希望使用 javascript 将所有表单输入设置为禁用。类似于:
您可以对每个输入元素执行此操作,其中“id”是该元素的 ID。
You would want to use javascript to set all the form inputs to disabled when the user checks the checkbox. Something like:
You would do this for each input element where 'id' is the ID of that element.
如果您只想禁用某些输入,最好枚举它们:
If you want to disable only certain inputs, It is a good idea to enumerate them:
您无法一次禁用整个表单。您确实需要禁用每个输入元素。基本上有两种方法可以实现这一目标。
第一种方法是在单击复选框时使用 Javascript 将表单提交到服务器,这样您就可以使用 JSF 组件的
disabled
属性来禁用元素。这是一个基本示例:这里
#{bean.freeze}
应指向boolean
属性。第二种方法是为此编写一个 Javascript 函数。这不需要表单提交,并且可以避免一个 HTTP 请求-响应周期,这有利于用户体验。
JS 函数
disableForm()
基本上很简单。只需通过this
将复选框作为函数参数传入,这样您就可以通过checkboxElement.form
获取父表单,然后通过form.elements< 获取所有表单元素/代码>。您只需要确保没有禁用复选框本身,这样您就可以再次重新启用表单:)
无需事先知道 ID,这使得 JS 代码通用且可重用。
You cannot disable an entire form at once. You really need to disable each of the input elements. There are basically two ways to achieve this.
First way is to use Javascript to submit the form to the server when the checkbox is clicked, so that you can use JSF component's
disabled
attribute to disable the elements. Here's a basic example:Here
#{bean.freeze}
should point to aboolean
property.Second way is to write a Javascript function for this. This does not require a form submit and saves you from one HTTP request-response cycle, which is better for user experience.
The JS function
disableForm()
is basically simple. Just pass the checkbox in as function argument bythis
so that you can get the parent form bycheckboxElement.form
and then get all form elements byform.elements
. You only need to make sure that you don't disable the checkbox itself, so that you could re-enable the form again :)No need to know the ID's beforehand and this makes the JS code generic and reuseable.