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

2019-03-03 14:58发布

I need my installer to accept a password, and so I've created a dialog on which users are prompted to enter their passwords twice (to avoid mistakes), however I'm having some trouble getting my "Your passwords don't match" label to appear and disappear at the correct times.

This is what I have so far:

<Control Id="Password" Type="Edit" Property="VDIR_PASSWORD" Password="yes" />
<Control Id="ConfirmPassword" Type="Edit" Property="ConfirmPassword" Password="yes" />
<Control Id="PasswordMismatchLabel" Type="Text" Text="Passwords do not match.">
  <Condition Action="hide">VDIR_PASSWORD = ConfirmPassword</Condition>
</Control>

This compiles, however does the label never shows. (if I reverse the condition then the label shows, but doesn't disappear if they don't match).

I can see that the thing I'm missing is subscription to some event that updates the label whenever something happens (e.g. the user presses a key, or focus is lost from either of the controls), however I'm not able to find any documentation or examples of how I might achieve this.

Is it possible to do this?

标签: wix condition
4条回答
仙女界的扛把子
2楼-- · 2019-03-03 15:08

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>
查看更多
Viruses.
3楼-- · 2019-03-03 15:14

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.

查看更多
Root(大扎)
4楼-- · 2019-03-03 15:25

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>
查看更多
Evening l夕情丶
5楼-- · 2019-03-03 15:29

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.

查看更多
登录 后发表回答