出现验证错误时,防止确认对话框打开 [英] Prevent confirmation dialogue from opening when there's a validation error

查看:140
本文介绍了出现验证错误时,防止确认对话框打开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在手风琴面板的标签内有一个文本区域,这是一个描述。我正在编辑一个描述并保存它。我正在验证文本区域,以便最大字符不应超过1000个字符。我正在使用< p:message> 来显示验证消息。在实际保存之前,将显示确认对话框以确认保存。

I have a text area inside a tab of accordion panel which is a description. I am trying to edit a description and saving it. I am validating the text area so that max character shouldn't exceed 1000 character. I am using <p:message> to display validation message. Before the actual save, a confirmation dialogue will be shown to confirm the save.

<p:messages showDetail="true" autoUpdate="true" />

<p:accordionPanel dynamic="true">
    <p:tab id="_0" title="description">
        <p:inputTextarea styleClass="max" id="editDesc1" widgetVar="txtBox" value="#{testBean.description}" 
            rows="6" cols="150" validatorMessage="#{msg.AddSystem_validationMsg5}" autoResize="false">
            <f:validateLength maximum="1000"></f:validateLength> 
        </p:inputTextarea>

        <p:commandButton value="save"  oncomplete="saveDialog.show()"/>

        <p:confirmDialog message="#{msg.EditSystem_confirmMsg1}" width="200" 
            showEffect="explode" hideEffect="explode" 
            header="Confirm" severity="alert" widgetVar="saveDialog"> 
            <p:commandButton value="#{msg.EditSystem_confirmAnswer1}"  action="#{testBean.saveEdit}" process="@this" /> 
            <p:commandButton value="#{msg.EditSystem_confirmAnswer2}" onclick="saveDialog.hide()" type="button" /> 

如果用户输入超过1000个字符并尝试保存,则出现验证消息短暂的时间,然后确认对话弹出,导致验证消息消失。

If an user enters more than 1000 characters and tries to save it, then the validation message appears for a short time and then the confirmation dialogue pops up, causing the validation message to disappear. How do I prevent the confirmation dialogue from popping up when there is a validation error?

推荐答案

您需要登录 oncomplete 保存按钮,如果验证没有失败。 PrimeFaces将一个全局的 args 对象放在JavaScript范围内,该范围依次具有一个布尔值 validationFailed 属性。你可以使用它:

You need to check in oncomplete of the save button if validation hasn't failed. PrimeFaces puts a global args object in the JavaScript scope which in turn has a boolean validationFailed property. You could make use of it:

<p:commandButton value="save" oncomplete="if (args &amp;&amp; !args.validationFailed) saveDialog.show()"/>

这样,只有验证没有失败,才会显示确认对话框。

This way the confirm dialog will only be shown if the validation has not failed.

这篇关于出现验证错误时,防止确认对话框打开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆