gpt4 book ai didi

javascript - 当 JavaScript 将 disabled 属性更改为 false 时,Commandbutton 不会调用操作

转载 作者:行者123 更新时间:2023-11-30 08:10:34 25 4
gpt4 key购买 nike

<分区>

我在 JSF + PrimeFaces 中构建了 Web 应用程序。在网络表单中,我将 primefaces 命令按钮的禁用属性设置为 true。在对表单输入字段执行自定义客户端验证后加载表单时,我根据表单上的用户输入将命令按钮的禁用属性设置为 false 或 true。注意:这里如果所有验证都通过按钮将被启用,但同时如果用户编辑某些输入并且验证失败则按钮将再次被禁用。

<p:commandButton id="saveButton" value="Save" actionListener="#{some method of bean}" 
update="component to update" disabled="true" />

但是按钮不能正常工作,我的意思是表单没有被提交。

但是如果按钮的 disabled 属性在开始时没有设置为 true,即使在自定义验证期间它被 javascript 禁用/启用(如上所述)它也能正常工作。

我不明白这个表单提交是如何依赖命令按钮的禁用属性的初始值的,即使我是通过 javascript 设置它的。

这是浏览器源代码中显示的 HTML 代码:

如果属性禁用设置为真:

<button id="saveButton" 
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
type="submit"
onclick="PrimeFaces.ab({formId:'createAccessPrivilegeForm',source:'saveButton',process:'@all',update:'centerPanel leftNavigationForm:leftNavigationTabView'});return false;"
name="saveButton"
role="button"
aria-disabled="false">

如果 disabled 属性设置为 false:

<button id="saveButton" 
class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-state-disabled"
disabled="disabled"
type="submit"
onclick="PrimeFaces.ab({formId:'createRoleForm',source:'saveButton',process:'@all',update:'centerPanel leftNavigationForm:leftNavigationTabView'});return false;"
name="saveButton"
role="button"
aria-disabled="true">

帮我解决这个问题。我希望命令按钮最初只被禁用,只有在验证通过后它才会被禁用,我希望它能够进行表单提交。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com