Combo
Combo is a typical combo box field. Combo Field is drop-down selection, which enables the user to select a value from the fixed list of values.
Adding list values in Combo:
Combo box allows adding two types of values through data-support class of the Form.
- Pre-Defined data values (See Adding Pre-Defined Data Values)
- Dynamic data values (See Adding Dynamic Data Values)
Alternatively, you can provide a list of values to a combo box through Canvas Studio itself. Refer Managing List of Values (LOV) for Form Fields for more information.
There might be situation where only single value is populated in the drop-down, in which case it makes sense to have the single value selected automatically instead of prompting users to select it. To achieve this, refer Automatic selection of value when drop-down contains single value.
- Form Items > Data Selection > Combo
The following table provides information about the properties that are applicable to this form item:
# | Property | Description | Sample Values |
---|---|---|---|
1 | Form ID | Unique ID of the Form on which you want to place the Form Item. | INVOICE_FORM |
2 | Item ID | Unique ID to the Form item. | INVOICE_TYPE |
3 | Item Type | To identify the item type in a form. | COMBO |
4 | Channel | Assigns the form item compatibility for various devices. | Desktop / Tablet / Mobile |
5 | Bundle Key | Name of the key associated with the property file which provides the localized label text for the current form item. | Common |
6 | Plain Label | Text entered in Plain Label field appears as the label of the form item without the resource bundle key translation. 18.1: If you are using the property files, leave the Plain Label field as blank. Display Name Key is the property-driven label key for the form item. 19.1: In Canvas 19.1, the Display Name Key field is a configuration-driven label key for the form item. See About Display Name Key and Plain Label from 19.1 and Managing Display Names for Forms for more information. | |
7 | Display Name Key | INVOICE TYPE | |
8 | Edit | Selected: Renders the Form in edit enabled mode. | Selected |
9 | Visibility | Selected: Shows the form item on the Form. | Selected |
10 | Help | Selected: Renders the form item with a help icon. | Selected |
11 | Anchor | Defines the size of the form item in terms of percentage (without % symbol). | 50 |
12 | Selected: Allows printing the form item while printing the form. | Selected | |
13 | Column Span | Occupies the specified number of item spaces horizontally for the current item. | 1 |
14 | Label Alignment | Indicates the alignment of the labels of the form items. | Top |
15 | Hide Label | Selected: Hides the label of the form item. | De-selected |
16 | Mandatory | Selected: Shows the red asterisk ({}{*}) on the label of the form item, and converts the particular field as mandatory. | Selected |
17 | Conditional Mandatory | Selected: Shows the blue double asterisks ({}{}) on the label of the form item, and converts the particular field as conditional mandatory. | De-Selected |
18 | Add Icon |
| De-Selected |
19 | Event Wiring | The Event Wiring option enables you to assign various events for different set of actions. For detailed information on Event Wiring, refer Form Items Event Wiring. | |
20 | Settings menu |
When both Raw Key-Raw Values (static data) and View ID-Key Column-Value Column (data from database) are specified, Canvas gives preference to Raw Key-Raw Values (static data).
| Y, N, I |
21 | Switch | Enables you to switch from one form item to another form item along with the applicable properties and their values. To switch from one form item to another form item, execute the steps that follow:
| NA |
22 | Clone | Enables you to create a duplicate of the selected form item along with its applicable properties except for the Item ID. | 2 |
Adding Pre-defined data values in Combo box:
After configuring the combo box, you can add the set of static or pre-configured data as its list values using the data support class. Write a Java class implementing the IadditionalDataSupport, which gets the source data and returns it to Canvas to fill them in the corresponding form item.
Assuming the item Id of the combo box is INVOICE_TYPE,
package com.intellectdesign.suppchain; import java.util.ArrayList; import java.util.HashMap; import com.intellectdesign.canvas.formdefinition.addinfo.AdditionalDataCodeValue; import com.intellectdesign.canvas.formdefinition.addinfo.DefaultAdditionalDataSupport; import com.intellectdesign.canvas.formdefinition.FormDefinitionException; import com.intellectdesign.canvas.formdefinition.FormItemDefinition; import com.intellectdesign.canvas.value.IUserValue; public class InvoiceDetailsDataSupport extends DefaultAdditionalDataSupport { public InvoiceDetailsDataSupport() { } public ArrayList getAdditionalDataFor(FormItemDefinition itemDefn, IUserValue userValue, HashMap inputParams) throws FormDefinitionException { ArrayList dataList = null; //Pass the Item ID of the combo as parameter if(itemDefn.getItemId().equals("INVOICE_TYPE")) { dataList = new ArrayList(); //Add the list of static values in the as Key, Value Pair dataList.add(new AdditionalDataCodeValue("CI", "Credit Invoice")); dataList.add(new AdditionalDataCodeValue("DI", "Debit Invoice")); } return dataList; } }
Adding dynamic data in Combo Box:
You can get the dynamic values from the database for the combo box using iBatis SQLMap configuration file. See section, Writing the SQLMap File and Instruction Class for more information about SQLMap file.
- Step 1: Create a SQLMap file with a unique ID.
- Step 2: After adding, get the data for the combo box using the Data Access Map Key.
Assuming the SQLMap file name is InvoiceSQLMap.xml,
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN" "http://ibatis.apache.org/dtd/sql-map-2.dtd"> <sqlMap> <resultMap id="INVOICE_TYPE_MAP" class="java.util.HashMap"> <result property="INV_TYPE_ID" nullValue="" column="INV_TYPE_ID" javaType="java.lang.String" jdbcType="VARCHAR2" /> <result property="INV_TYPE" nullValue="" column="INV_TYPE" javaType="java.lang.String" jdbcType="VARCHAR2" /> <result property="TOTAL_COUNT" nullValue=""column="TOTAL_COUNT" javaType="java.lang.String" jdbcType="VARCHAR2" /> </resultMap> <sql id ="INVOICE_TYPE"> SELECT INV_TYPE_ID, INV_TYPE <include refid = "NEW_DEFAULT_ORDERBY_CLAUSE"/> FROM INV_TYPE_MASTER </sql> <select id="INVOICE_TYPE_MAP_SELECT_INV_TYPE" resultMap = "INVOICE_TYPE_MAP"> <include refid="INVOICE_TYPE"/> </select> </sqlMap>
Assuming the same item Id INVOICE_TYPE, the data-support class would be as follows:
package com.intellectdesign.suppchain; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import jave.util.Map; import com.intellectdesign.canvas.formdefinition.addinfo.AdditionalDataCodeValue; import com.intellectdesign.canvas.formdefinition.addinfo.DefaultAdditionalDataSupport; import com.intellectdesign.canvas.formdefinition.FormDefinitionException; import com.intellectdesign.canvas.formdefinition.FormItemDefinition; import com.intellectdesign.canvas.value.IUserValue; import com.intellectdesign.canvas.database.*; public class InvoiceDetailsDataSupport extends DefaultAdditionalDataSupport { public InvoiceDetailsDataSupport() {} public ArrayList getAdditionalDataFor(FormItemDefinition itemDefn, IUserValue userValue, HashMap inputParams) throws FormDefinitionException { ArrayList<AdditionalDataCodeValue> resultList = null; DatabaseRequest dbRequest = null; DatabaseResult dbResult = null; List tmpList = null; String key = null; String value = null; try { dbRequest = new DatabaseRequest(); dbResult = new DatabaseResult(); tmpList = new ArrayList(); resultList = new ArrayList<AdditionalDataCodeValue>(); dbRequest.setDataSource(DatabaseConstants.DEFAULT_DATASOURCE); if(itemDefn.getItemId().equals("INVOICE_TYPE")) { dbRequest.setOperation(DatabaseConstants.SELECT); // Pass the SQL Map ID which is added in the Select tag dbRequest.setDataAccessMapKey("INVOICE_TYPE_MAP"); // Pass the Extended SQL ID dbRequest.setOperationExtension("INV_TYPE"); dbResult = dbRequest.execute(); key = "INV_TYPE_ID"; value = "INV_TYPE"; tmpList = dbResult.getReturnedList(); } for(int i=0;i<tmpList.size();i++) { Map tmpMap = (HashMap)tmpList.get(i); resultList.add(new AdditionalDataCodeValue((String)tmpMap.get(key), (String)tmpMap.get(value))); } } catch(DatabaseException dbExcep) { throw new FormDefinitionException(dbExcep); } return resultList; } }
Automatic selection of value when drop-down contains single value
You can enable automatic selection of value in the drop-down when there is only single value in the drop-down instead of prompting users to select the single value. You can achieve this by using the 'defaultSelectIfSingleValue' property, which is applicable at the form-item level. The default value is 'False'. The 'defaultSelectIfSingleValue' property must be set to 'True' for automatic selection of single value in the drop-down and must be given in the respective form listener JS file.
The 'defaultSelectIfSingleValue' property can be used for the following form-items: Combo Box, Icon Combo Box, and Auto Suggest.
Consider a scenario where the Invoice Type combo box will have only Debit Invoice as the value in the drop-down. A sample usage of '' for the specified scenario is provided for reference as follows:
// Sample listener JS canvas.form.listeners.INVOICE_FORM = Class(canvas.Observable, { constructor: function(config) { this.fm = config.fm; }, registerHandlers: function() { this.fm.registerHandler(CFEC.PRE_INITIALIZE, function(fm, event, fieldName, value) { return { 'INVOICE_TYPE': // Combo Box item ID { 'defaultSelectlIfSingleValue': true }, }; }); } }); CFLR.registerListener("INVOICE_FORM", canvas.form.listeners.SAMPLE_FORM); // INVOICE_FORM is the Form ID