Ven
Ven

Reputation: 255

Associate Feature to Checkbox in WiX

I have a few features (Complete, which has 2 child features, namely AppFeature and DBFeature) in my Product.wxs, as shown below.

 <Feature InstallDefault="local" Description="!(loc.FullFeatureDesc)" Title="!(loc.FullFeatureTitle)" Level="1" Id="Complete" Absent="allow" AllowAdvertise="no" Display="expand">
      <Feature InstallDefault="local" Description="!(loc.AppFeatureDesc)" Title="!(loc.AppFeatureTitle)" Level="1" Id="AppFeature" Absent="allow" AllowAdvertise="no" Display="expand">
        <ComponentGroupRef Id="AppCG"/>
      </Feature>
      <Feature InstallDefault="local" Description="!(loc.DBFeatureDesc)" Title="!(loc.DBFeatureTitle)" Level="1" Id="DBFeature" Absent="allow" AllowAdvertise="no" Display="expand">
        <ComponentGroupRef Id="DbCG"/>
      </Feature>
    </Feature>

In another dialog, I have a few checkboxes for All, App and DB options, each meant for a feature (All means both App and DB). I want to associate App checkbox to App feature and DB checkbox to DB Feature. I tried it using Publish element in the Next button on that dialog using the Event="AddLocal" and Value="AppFeature" and one for DBFeature with the checkbox values checked appropriately. But on clicking on Next button, nothing happens. Can anyone please help me? I am also providing the elements on the dialog for reference.

<Control Id="ControlAllFeature" Type="CheckBox" X="180" Y="33" Width="140" Height="17"
    Property="ALLFEATURES_CHECKED" CheckBoxValue="AllFeatureValue" Text="Install Everything">
          <Publish Property="APPFEATURE_CHECKED" Value="AppFeatureValue" Order="1">ALLFEATURES_CHECKED</Publish>
          <Publish Property="APPFEATURE_CHECKED" Value="{}" Order="2">NOT ALLFEATURES_CHECKED</Publish>
          <Publish Property="DBFEATURE_CHECKED" Value="DBFeatureValue" Order="3">ALLFEATURES_CHECKED</Publish>
          <Publish Property="DBFEATURE_CHECKED" Value="{}" Order="4">NOT ALLFEATURES_CHECKED</Publish>      
        </Control>
        <Control Id="ControlAppFeature" Type="CheckBox" X="191" Y="50" Width="140" Height="17"
     Property="APPFEATURE_CHECKED" CheckBoxValue="AppFeatureValue" Text="Install Application">
          <Publish Property="ALLFEATURES_CHECKED" Value="{}" Order="1">NOT APPFEATURE_CHECKED</Publish>
          <Publish Property="ALLFEATURES_CHECKED" Value="AllFeatureValue" Order="2">APPFEATURE_CHECKED AND DBFEATURE_CHECKED</Publish>
        </Control>
        <Control Id="ControlDBFeature" Type="CheckBox" X="191" Y="67" Width="140" Height="17"
           Property="DBFEATURE_CHECKED" CheckBoxValue="DBFeatureValue" Text="Install DB">
          <Publish Property="ALLFEATURES_CHECKED" Value="{}" Order="1">NOT DBFEATURE_CHECKED</Publish>
          <Publish Property="ALLFEATURES_CHECKED" Value="AllFeatureValue" Order="2">APPFEATURE_CHECKED AND DBFEATURE_CHECKED</Publish>
        </Control>

        <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&amp;Back">
          <Publish Event="NewDialog" Value="CustLicenseAgmtDlg">1</Publish>
        </Control>
        <Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&amp;Next">
          <Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">CostingComplete = 1</Publish>
          <Publish Event="NewDialog" Value="BrowsePathDlg"></Publish>
           <Condition Action="disable">NOT APPFEATURE_CHECKED OR NOT DBFEATURE_CHECKED</Condition>
          <Condition Action="enable">APPFEATURE_CHECKED OR DBFEATURE_CHECKED</Condition>
         <Publish Event="Remove" Value="ALL" Order="1">1</Publish>
         <Publish Event="AddLocal" Value="AppFeature" Order="2">APPFEATURE_CHECKED</Publish>
         <Publish Event="AddLocal" Value="DBFeature" Order="3">DBFEATURE_CHECKED</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>

I referred the link below for this, but couldn't get it working. Any help will be really appreciated.

Wix 3.5, Install features based on checkboxes

Upvotes: 0

Views: 434

Answers (2)

Ven
Ven

Reputation: 255

I changed the approach. There are actually 2 ways. One is to do it in Product.wxs within the feature elements to have a condition. The other one gives better control. The mark up below explains it.

<Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&amp;Next">
          <Publish Event="SpawnWaitDialog" Value="WaitForCostingDlg">CostingComplete = 1</Publish>
          <Publish Event="NewDialog" Value="BrowsePathDlg">1</Publish>
             <Condition Action="disable">NOT APPFEATURE_CHECKED OR NOT DBFEATURE_CHECKED OR (((!AppFeature = 3) AND (!DBFeature = 2) AND NOT DBFEATURE_CHECKED) AND ((!DBFeature = 3) AND (!AppFeature = 2) AND NOT APPFEATURE_CHECKED)) OR ((!AppFeature = 3) AND (!DBFeature = 3))</Condition>
          <Condition Action="enable">(APPFEATURE_CHECKED OR DBFEATURE_CHECKED) AND (((!AppFeature = 2) AND APPFEATURE_CHECKED) OR ((!DBFeature = 2) AND DBFEATURE_CHECKED))</Condition>
           <Publish Event="AddLocal" Value="ALL">1</Publish> 
          <Publish Event="Remove" Value="AppFeature"><![CDATA[APPFEATURE_CHECKED <> "1"]]></Publish>
          <Publish Event="Remove" Value="DBFeature"><![CDATA[DBFEATURE_CHECKED <> "1"]]></Publish>
        </Control>

What I was missing earlier was the value of 1 in the Publish NewDialog event. Once I added it, it started working and clicking on the Next button, took me to the next dialog.

Upvotes: 1

polzka90
polzka90

Reputation: 123

Try this:

in your chield feature put it in level 0, and them put a condition inside her to validate if the checkbox was checked

<Feature InstallDefault="local" Description="!(loc.FullFeatureDesc)" Title="!(loc.FullFeatureTitle)" Level="1" Id="Complete" Absent="allow" AllowAdvertise="no" Display="expand">
  <Feature InstallDefault="local" Description="!(loc.AppFeatureDesc)" Title="!(loc.AppFeatureTitle)" Level="0" Id="AppFeature" Absent="allow" AllowAdvertise="no" Display="expand">
    <ComponentGroupRef Id="AppCG"/><Condition Level="1">APPFEATURE_CHECKED</Condition>
  </Feature>
  <Feature InstallDefault="local" Description="!(loc.DBFeatureDesc)" Title="!(loc.DBFeatureTitle)" Level="1" Id="DBFeature" Absent="allow" AllowAdvertise="no" Display="expand">
    <ComponentGroupRef Id="DbCG"/>
  </Feature>
</Feature>

Upvotes: 0

Related Questions