JSF 文本字段 onchange 提交选项卡

发布于 2024-10-09 01:14:21 字数 371 浏览 0 评论 0原文

我有多个文本字段,每个字段都有 onChange="submit();"以便立即保存数据。我遇到的问题是,按 Tab 键切换到下一个字段将不起作用,因为它将提交,然后由于页面提交而失去对该字段的焦点。此外,如果用户要单击他们想要编辑的下一个文本字段,它将失去焦点,并且由于页面提交,他将不得不再次单击它。是否有办法解决此问题,以便在页面提交后它将焦点设置到预期的文本字段?

背景:

我有一个动态表,它是通过这些多个字段填充的。用户将从下拉列表中选择一个值,然后单击“新建”按钮,然后将显示与所选值对应的所有字段。我决定让每个文本字段提交 onChange 而不是提交按钮,以减少由于所有输入数据的复杂性而导致的页面混乱。另外,表格和其他所有内容都会自动更新,这看起来更酷。

谢谢。

I have multiple text fields that each have onChange="submit();" in order to save the data immediately. The problem I have is that tabbing to the next field won't work because it will submit and then loses focus on the field due to the page submition. Also, if the user is to click the next text field they want to edit it will lose focus and he will have to click it a second time due to the page submition. Is there anyway to fix this so that after the page submits it will set the focus to the intended text field?

Background:

I have a dynamic table that is being populated via these multiple fields. The user will select a value from a dropdown list and then click "New" button and then all the fields corresponding with the selected value will appear. I decided to have each text field submit onChange instead of a submit button in order to reduce the clutter on the page due to the complexity of all the input data. Plus it just seems cooler that the table and everything else gets updated automatically.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2024-10-16 01:14:21

我遇到的问题是,按 Tab 键切换到下一个字段不起作用,因为它将提交,然后由于页面提交而失去对该字段的焦点。

是的,每当您触发 onchange 事件时,您的表单都会被提交,而当 JSF 生命周期结束时,您的页面会再次呈现,并且您会失去焦点。

在我看来,您有多个输入测试,并且想要动态重新渲染表格。为什么你不尝试使用 ajax 的另一种方法?首先使用 ajax 处理输入字段,然后动态重新呈现表格。

例子:

<h:inputText id="input" value="#{mybean.input}" >
    <a4j:support 
        event="onchange"
        ajaxSingle="true"
        action="#{mybean.doSomething()}" 
        reRender="myTable" />
</h:inputText>

The problem I have is that tabbing to the next field won't work because it will submit and then loses focus on the field due to the page submition.

Yes, any time you trigger the onchange event your form is submited and when the JSF life Cycle ends your page is rendered again and you lose the focus.

It sounds to me like you have several input test and you want to rerender a table dynamically. Why you don't try another approach with ajax ? First process your input fields with ajax and then rerender your table dynamically.

Example:

<h:inputText id="input" value="#{mybean.input}" >
    <a4j:support 
        event="onchange"
        ajaxSingle="true"
        action="#{mybean.doSomething()}" 
        reRender="myTable" />
</h:inputText>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文