How to add a default value for Combobox

Hello, I am currently trying to create a combobox of the contacts associated with a certain account. When a contact is selected, then that contact will be made the primary contact.

 

Everything works fine, but when the edit page first launches the combobox does not display the primary contact and appears as it does below.

How would I get the combobox to display the primary contact on initialization like below.

Here is my replacing client schema:

define("AccountPageV2", [],function() {
    return {
        entitySchemaName: "Account",
        details: /**SCHEMA_DETAILS*/{}/**SCHEMA_DETAILS*/,
        attributes: {
            "myEnum": {
                "dataValueType": Terrasoft.DataValueType.ENUM,
                "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
                "caption": "Primary Contact:"
            },
            "myList": {
                "dataValueType": Terrasoft.DataValueType.ENUM,
                "type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN,
                "isCollection": true
            }
        },
        diff: /**SCHEMA_DIFF*/[
            {
                "operation": "insert",
                "name": "myEnum",
                "values": {
                    "caption": "myEnum",
                    "dataValueType": this.Terrasoft.DataValueType.ENUM,
                    "bindTo": "myEnum",
                    "layout": { "colSpan": 24, "rowSpan": 1, "column": 0, "row": 4 },
                    "controlConfig": {
                        "className": "Terrasoft.ComboBoxEdit",
                        "list": {
                            "bindTo": "myList"
                        },
                        "change": {
                            "bindTo": "onMyValueChange"
                        },
                        "prepareList": {
                            "bindTo": "prepareMyList"
                        }
                    }
                },
                "parentName": "SolutionTab_gridLayout",
                "propertyName": "items",
                "index": 1
            }
        ]/**SCHEMA_DIFF*/,
        methods: {
            onPageInitialized: function(callback, scope) {
                if (!this.get("myList")) {
                    this.set("myList", this.Ext.create("Terrasoft.Collection"));
                }
 
                if (callback) {
                    callback.call(scope || this);
                }
            },
            onEntityInitialized: function() {
                this.callParent(arguments);
            },
            prepareMyList: function(filter, list) {
				if (list === null) {
                    return;
                }
                list.clear();
				// create query for server side
				var esq = this.Ext.create("Terrasoft.EntitySchemaQuery", {
					rootSchemaName: "Contact"
				});
				esq.addColumn("Name", "Name");
				esq.addColumn("Id", "Id");
				esq.addColumn("Account.Id","Account");
				esq.addColumn("Job.Name","Job");
				// run query
				var filterAccountType = esq.createColumnFilterWithParameter(
						Terrasoft.ComparisonType.EQUAL, "Account", this.get("Id"));
				esq.filters.addItem(filterAccountType);
				esq.getEntityCollection(function(result) {
					//perform
					if (!result.success) {
						/* For example, error processing/logging. */
						this.showInformationDialog("Data query error");
						return;
					}
					var count = 0;
					var items = {};
					result.collection.each(function (item) {
						items[item.get("Id")] = {
							"value": item.get("Id"),
							"displayValue": item.get("Name")+ "  :  " + item.get("Job")
						};
					});
					var list = this.get("myList");
					list.loadAll(items);
				}, this);
            },
            onMyValueChange: function(val) {
                if (val) {
                    console.log("New Primary Contact Added");
					this.set('PrimaryContact',val);
                }
            }
        },
        rules: {}
    };
});

 

Like 0

Like

4 comments
Best reply

Dominic Ricci,

Since the Comboxbox is bound to the myEnum attribute, you should be able to set the default as something like this: 

this.set("myEnum", { 
    value: "DefaultIdValue", 
    displayValue: "DefaultTextValue" 
});

Ryan

Hi,

Hard to tell the problem based on the code alone. In this case, you need to do a debug to find the cause.

Maybe this example may help you, the task of setting a default value is quite similar to your case.

Dmytro Vovchenko,

In the example you link there is the line of code



this.set("Deadline", newDate);

 

How would I do this for the combobox? Maybe something like this...

 

value = this.get("Primary Contact");

this.set("myEnum", value);



The issue is that I do not know how to access the initialized value in the combobox. Is the assumption of setting myEnum correct? 

Dominic Ricci,

Since the Comboxbox is bound to the myEnum attribute, you should be able to set the default as something like this: 

this.set("myEnum", { 
    value: "DefaultIdValue", 
    displayValue: "DefaultTextValue" 
});

Ryan

Ryan Farley,

This is what I was looking for. Thank you!

Show all comments