NotDan
NotDan

Reputation: 32213

How do I require a value in a textbox in a Wix custom dialog?

I have a Wix dialog with a control of type edit (which is a uri of a server the service depends on).

How can I disable the Next button until a value has been input?

Upvotes: 9

Views: 4529

Answers (3)

Lukas
Lukas

Reputation: 136

It is really easy to enable or disable a button on a custom form, based on data entered. Here is the next button in a custom dialog:

    <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="!(loc.WixUINext)">
      <Condition Action="enable"><![CDATA[TARGET_ENVIRONMENT<>""]]></Condition>
      <Condition Action="disable"><![CDATA[TARGET_ENVIRONMENT~=""]]></Condition>
    </Control>

The next button gets enabled automatically as soon as text is not empty. No error dialog needed. We use this with a dropdown, but it works with text box as well.

Upvotes: 0

saschabeaumont
saschabeaumont

Reputation: 22406

Here's an excerpt from some (old) production code we used to use:

<Dialog Id="MyDlg_Error" Width="260" Height="85" NoMinimize="yes" Title="!(loc.MyDlg_Title)">
    <Control Id="MyDlgSkipDesc" Type="Text" Width="194" X="48" Y="15" Height="30" Text="!(loc.MyDlg_ErrorMsg)" />
    <Control Id="Ok" Type="PushButton" X="97" Y="57" Width="66" Height="17" Text="!(loc.WixUIOK)" />
</Dialog>

<Publish Dialog="MyDlg" Control="Next" Event="SpawnDialog" Value="MyDlg_Error"><![CDATA[Not (MY_REQUIRED_FIELD <> "")]]></Publish>

<Publish Dialog="MyDlg_Error" Control="Ok" Event="EndDialog" Value="Return">1</Publish>

Upvotes: 11

Bob Arnson
Bob Arnson

Reputation: 21886

There's no reasonable way to do that. Instead, leave Next enabled and do your check with a SpawnDialog control event tied to Next that shows an error if the property is empty. It also lets you run a validation custom action if you want something more useful that "not empty."

Upvotes: 3

Related Questions