WIX UI - Creating a “passwords don't match” label

百般思念 提交于 2019-12-02 08:34:22

WiX can only do what underlying technology (Windows Installer) can. Windows Installer has poor UI comparing to usual desktop applications we all used to. So, answering your question: no, you can't show/hide the label based on the value you've typed into the password field. At least, I'm not aware about a supported way.

However, you can do the following. Drop that label, and instead add a condition to the Next button of this dialog. If passwords match, move to the next dialog in the chain. Otherwise, show a message box saying "password don't match" and stay on the current dialog until the user fills it in correctly.

Hope this helps.

Here is an example of what Yan is suggesting:

<Control Id="Next" Type="PushButton" X="238" Y="243" Width="56" Height="17" Text="Next">
  <Publish Event="NewDialog" Value="VirtualDirectoryDlg">1</Publish>
  <Condition Action="disable">
    <![CDATA[(ACCOUNT_TYPE = "Service" AND WEB_APP_POOL_SERVICE_NAME = "") OR 
                             (ACCOUNT_TYPE = "User" AND 
                                                      ((WEB_APP_POOL_IDENTITY_DOMAIN = "" OR 
                                                       WEB_APP_POOL_IDENTITY_NAME = ""   OR 
                                                       WEB_APP_POOL_IDENTITY_PWD = ""    OR 
                                                       WEB_APP_POOL_IDENTITY_PWD_CONFIRM = "") OR (WEB_APP_POOL_IDENTITY_PWD <> WEB_APP_POOL_IDENTITY_PWD_CONFIRM))) ]]>
  </Condition>
  <Condition Action="enable">
    <![CDATA[(ACCOUNT_TYPE = "Service" AND WEB_APP_POOL_SERVICE_NAME <> "") OR 
                             (ACCOUNT_TYPE = "User" AND 
                                                      ((WEB_APP_POOL_IDENTITY_DOMAIN <> "" AND 
                                                       WEB_APP_POOL_IDENTITY_NAME <> ""   AND 
                                                       WEB_APP_POOL_IDENTITY_PWD <> ""    AND
                                                       WEB_APP_POOL_IDENTITY_PWD_CONFIRM <> "") AND (WEB_APP_POOL_IDENTITY_PWD = WEB_APP_POOL_IDENTITY_PWD_CONFIRM))) ]]>
  </Condition>
</Control>

Here's the approach I took to solve this issue. This solution does not rely on disabling the "Next" button. Instead, it recognizes three states during the password comparison, but doesn't allow a user to proceed unless 1) both the password fields are populated, and 2) both password fields match. This solution also provides text labels to let the user better understand when there are errors states.

Hopefully this solution will help others.

The three states:

  • Passwords match
  • Passwords do not match
  • Passwords match, but are empty strings

Error states:

  • "Passwords do not match"
  • "Password fields required"

To get the red, slightly larger than normal text, by adding the following TextStyle element into my primary wxs file (e.g. product.wxs).

<UI>
      <TextStyle Id="WixUI_Font_Large_Red" FaceName="Tahoma" Size="9" Red="255" />
</UI>

Here's the

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
    <Property Id="PASSWORD_COMPARE" Value="1" />
    <UI>
        <Dialog Id="ConfirmPasswordDlg" Width="370" Height="270" Title="Confirm Password Demo">
            <Control Id="PasswdLabel" Type="Text" X="25" Y="65" Width="90" Height="15" TabSkip="no" Text="Password:" RightAligned="yes" />
            <Control Id="PasswdEdit" Type="Edit" X="117" Y="62" Width="175" Height="16" Property="PASSWD" Text="{80}" Password="yes"></Control>
            <Control Id="ConfirmPasswdLabel" Type="Text" X="25" Y="90" Width="90" Height="15" TabSkip="no" Text="Confirm Password:" RightAligned="yes" />
            <Control Id="ConfirmPasswdEdit" Type="Edit" X="117" Y="87" Width="175" Height="16" Property="PASSWD_CONFIRM" Text="{80}" Password="yes"></Control>
            <Control Id="PasswordsMatchLabel" Type="Text" X="150" Y="110" Width="140" Height="18" Text="{\WixUI_Font_Large_Red}Passwords do not match">
                <Condition Action="hide">(PASSWORD_COMPARE = "1")</Condition>  
                <Condition Action="show">(PASSWORD_COMPARE = "2")</Condition>
                <Condition Action="hide">(PASSWORD_COMPARE = "3")</Condition>
            </Control>
            <Control Id="PasswordsRequiredLabel" Type="Text" X="150" Y="110" Width="140" Height="18" Text="{\WixUI_Font_Large_Red}Password fields required">
                <Condition Action="hide">(PASSWORD_COMPARE = "1")</Condition>  
                <Condition Action="hide">(PASSWORD_COMPARE = "2")</Condition>
                <Condition Action="show">(PASSWORD_COMPARE = "3")</Condition>
            </Control>
            <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="Back"></Control>
            <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="Next">
                <Publish Property="PASSWORD_COMPARE" Value="1" Order="1">
                    <![CDATA[ (PASSWD = PASSWD_CONFIRM) ]]>
                </Publish>
                <Publish Property="PASSWORD_COMPARE" Value="2" Order="2">
                    <![CDATA[ (PASSWD <> PASSWD_CONFIRM) ]]>
                </Publish>
                <Publish Property="PASSWORD_COMPARE" Value="3" Order="3">
                    <![CDATA[ (PASSWD = "" AND PASSWD_CONFIRM = "") ]]>
                </Publish>
                <Publish Event="NewDialog" Value="VerifyReadyDlg" Order="4">PASSWORD_COMPARE = "1"</Publish>
            </Control>
            <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">
                <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
            </Control>
        </Dialog>
    </UI>
</Fragment>
</Wix>

As far as I'm aware, there is no event subscription model in Wix. What you'll likely have to do is create a custom action to verify that the passwords match and have that control the label. This may help also.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!