Hi Community,
How can i make checkbox visible/hidden based on previous DropDown value.
For ex - I have dropdown field as Product having values - KFC, Pizzahut.
I have different checkboxes values if user selects KFC or Pizzahut.
How can i show different checbox dynamically after user selects dropdwon value.
I don't want to show all checkbox value and then hide. Based on the choice KFC/Pizzahut corresponding Checkbox options should dynamically come in form.
Here is the code that i am trying. Please help me with this.
if( ri!readOnly, a!textField( label: "Product", labelPosition: "ADJACENT", value: ri!record.productGroupAffected.value, readOnly: true ), a!dropdownField( label: "Product", labelPosition: "ABOVE", instructions: "", helpTooltip: "", placeholderLabel: "--- Select a Value ---", choiceLabels: local!productGroupAffectedOptions.value, choiceValues: local!productGroupAffectedOptions, value: ri!record.productGroupAffected, saveInto: ri!record.productGroupAffected, required: false ) ), if( ri!record.productGroupAffected = "KFC", a!textField( label: "Tools Affected KFC", labelPosition: "ADJACENT", value: if( or(isnull(ri!record.toolsAffected), count(ri!record.toolsAffected.value)=0), "", joinarray(ri!record.toolsAffected.value, ", ") ), readOnly: true ), a!checkboxField( label: "Tools Affected KFC", labelPosition: "ABOVE", instructions: "", helpTooltip: "", choiceLabels: local!checkbox1Value, choiceValues: local!checkbox1Value, value: ri!record.toolsAffected, saveInto: ri!record.toolsAffected, required: false ) ), if( ri!record.productGroupAffected = "PizzaHut", a!textField( label: "Tools Affected PizzaHut", labelPosition: "ADJACENT", value: if( or(isnull(ri!record.toolsAffected), count(ri!record.toolsAffected.value)=0), "", joinarray(ri!record.toolsAffected.value, ", ") ), readOnly: true ), a!checkboxField( label: "Tools Affected PizzaHut", labelPosition: "ABOVE", instructions: "", helpTooltip: "", choiceLabels: local!checkbox2Value, choiceValues: local!checkbox2Value, value: ri!record.toolsAffected, saveInto: ri!record.toolsAffected, required: false ) ),
Discussion posts and replies are publicly visible
I was able to get it working - basically it required somewhat different handling of the local variable being used to store sizes, storing it as an array instead of a singular in the local dictionary, and special handling for when the user de-selects back down to the empty set.
load( local!restaurantChoices: { {id: 1, name: "KFC"}, {id: 2, name: "Pizza Hut"} }, local!selectedRestaurant, local!menuSelection: {}, /* set up Menu Selection Sizes to be an array of dictionary - the CDT would resemble {item: "item name", size: sizeId} */ local!menuSelectionSizes: {}, with( /* dynamically set the menu choices based on which restaurant is picked */ local!menuChoices: if( isnull(local!selectedRestaurant), {}, if( tointeger(local!selectedRestaurant) = 1, { "Fried Chicken", "Mashed Potatoes", "Cole Slaw", "Biscuits", "Gravy" }, if( tointeger(local!selectedRestaurant) = 2, { "Pizza", "Bread Sticks", "Salad Bar", "Soft Drinks" }, {} ) ) ), a!formLayout( /* now assuming 17.2 or newer */ contents: { a!radioButtonField( label: "Chain:", labelPosition: "ADJACENT", choiceLabels: local!restaurantChoices.name, choiceValues: local!restaurantChoices.id, value: local!selectedRestaurant, saveInto: { local!selectedRestaurant, /* the below will clear the previous menu selection when the restaurant is changed */ a!save( local!menuSelection, {} ) } ), if( not(isnull(local!selectedRestaurant)), a!checkBoxField( label: "Make your food choices:", labelPosition: "ADJACENT", choiceLabels: local!menuChoices, choiceValues: local!menuChoices, value: local!menuSelection, saveInto: { a!save( local!menuSelection, /* this weird saveInto style will attempt to keep the saved value array in the same order as the initial checkboxes, since Appian versions 17.1 and later no longer do this automatically */ index( local!menuChoices, whereContains( save!value, local!menuChoices ) ) ) } ), {} ), a!columnsLayout( columns: a!forEach( local!menuSelection, with( local!currentIndex: wherecontains( fv!item, touniformstring(property(local!menuSelectionSizes, "item", {})) ), a!columnLayout( contents: { a!checkboxField( label: "Select Size: '" & fv!item & "'", labelPosition: "ABOVE", choiceLabels: {"Small", "Medium", "Large"}, choiceValues: {1, 2, 3}, value: tointeger( property( index( local!menuSelectionSizes, local!currentIndex, null() ), "sizes", null() ) ), saveInto: { a!save( local!menuSelectionSizes, append( if( isnull(local!currentIndex), local!menuSelectionSizes, remove(local!menuSelectionSizes, local!currentIndex) ), if( apn_isEmpty(save!value), /* indicates all size choices have been de-selected, so we'll save an empty set here to remove this menu choice from the saved data set */ {}, { item: fv!item, sizes: save!value } ) ) ) } ) } ) ) ) ), /*a!paragraphField(*/ /*label: "debug",*/ /*value: local!menuSelectionSizes*/ /*),*/ {} } ) ) )
I have problem with rule Inputs when i am translating the code for Rule Inputs. Here is the part of code that i am using for my application and looking for the explanation of this part of answer suggested by you -
a!columnsLayout( columns: a!forEach( ri!CCC.toolsaffected, with( local!currentIndex: wherecontains( fv!item, touniformstring(property(ri!CCC.NodesAffected, "item", {})) ), a!columnLayout( contents: { a!checkboxField( label: "Nodes Affected for : '" & fv!item & "'", labelPosition: "ABOVE", /*instructions: "current index: " & local!currentIndex,*/ choiceLabels: {"1262", "1264", "1266","1268","1270","1272","1274","1276"}, choiceValues: {1262, 1264, 1266, 1268, 1270, 1272, 1274, 1276}, value: tointeger( property( index( ri!CCC.NodesAffected, local!currentIndex, null() ), "nodes", null() ) ), saveInto: { a!save( ri!CCC.NodesAffected, append( if(isnull(local!currentIndex), ri!CCC.NodesAffected, remove(ri!CCC.NodesAffected, local!currentIndex) ), if( rule!APN_isEmpty(save!value), /* indicates all size choices have been de-selected, so we'll save an empty set here to remove this menu choice from the saved data set */ {}, { item: fv!item, nodes: save!value } ) ) ) } ) } ) ) ), showwhen: not(isnull(ri!CCC.ProductGroupAffected)) ),
Here is the XSD of the CDT -
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:com:appian:types:CCCD" targetNamespace="urn:com:appian:types:CCCD"> <xsd:complexType name="CCC_Details"> <xsd:annotation> <xsd:documentation><![CDATA[Information]]></xsd:documentation> </xsd:annotation> <xsd:sequence> <xsd:element name="CCCNumber" nillable="true" type="xsd:int"> <xsd:annotation> <xsd:appinfo source="appian.jpa">@Id @GeneratedValue</xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="Approved" nillable="true" type="xsd:string"> <xsd:annotation> <xsd:appinfo source="appian.jpa">@Column(length=50)</xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="ApprovalDate" nillable="true" type="xsd:date" /> <xsd:element name="PRNumber" nillable="true" type="xsd:int" /> <xsd:element name="ProductGroupAffected" nillable="true" type="xsd:string" /> <xsd:element maxOccurs="unbounded" minOccurs="0" name="ToolsAffected" nillable="true" type="xsd:string" /> <xsd:element maxOccurs="unbounded" minOccurs="0" name="NodesAffected" nillable="true" type="xsd:string" /> <xsd:element name="ApprovedBy" nillable="true" type="xsd:string"> <xsd:element name="Bundled" nillable="true" type="xsd:string"> <xsd:annotation> <xsd:appinfo source="appian.jpa">@Column(length=5)</xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="CreatedBy" nillable="true" type="xsd:string"> <xsd:annotation> <xsd:appinfo source="appian.jpa">@Column(length=100)</xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="CreatedOn" nillable="true" type="xsd:dateTime" /> <xsd:element name="UpdatedBy" nillable="true" type="xsd:string"> <xsd:annotation> <xsd:appinfo source="appian.jpa">@Column(length=100)</xsd:appinfo> </xsd:annotation> </xsd:element> <xsd:element name="UpdatedOn" nillable="true" type="xsd:dateTime" /> </xsd:sequence> </xsd:complexType> </xsd:schema>
My problem is same as earlier. Still if i click one of the Nodes Affected ( Product Sizes in earlier examples ) and then select the some other from list of checkboxes, my previous selection gets removed. However it is working fine for the code you mentioned above using local variables but not working with rule inputs.