'Selected' default not working?

Hello,

I have a form bound to a grid control.

I want the default dropdown option on a form field to be autoselected. My code is:

            type: "select",
            name: "ActivityStatus",
            label: "Active",
            value: "",
            options:
            [
            	    {text: "Yes", value: "Y"},            	    
            	    {text: "No",  value: "N", selected: "true"},
            ],            
            required: false  	

The form doesn’t autoselect the ‘N’ value. Why, please? Does it have something to do with the form being bound to the grid? The simple examples you show online seem to work, and the code is no different than mine, from what I can tell. Sample code would be appreciated. Thanks.

Just clean the quotes.
{text: “No”, value: “N”, selected: true},

Thanks, Darya, but removing the quotes around the Boolean value didn’t work, either. I refreshed the browser and look at the dropdown, and there was no change.

Any other suggestions, please? Thanks.

Locally it works.
Means, make a completed demo and attach here.
docs.dhtmlx.com/doku.php?id=othe … leted_demo

Thanks, Darya. I can get the dropdown select to work locally here, using a very simple example. It doesn’t work in the app I wrote, which involves a number of objects (form, grids) sharing a datastore and bound to each other.

I’ll look through the link you sent and try to provide you the code in the format you request. Thank you again.

Ok
Provide it, when you can.

Hi, Darya,

Attached, please find completed demo.

Thank you!

I’ve downloaded your demo. Don’t attach PROF js files here, please. In PM or in SUPPORT only.
Wait for answer.

Сould you provide us a completed demo corresponding to our requirements by link?
docs.dhtmlx.com/doku.php?id=othe … leted_demo
And ONLY with your form. Not the whole project.

Darya, I’m sorry, I don’t understand what you are asking for. I believe I gave you a ‘complete demo’ in line with your requirements. Please advise? Thank you.

Sorry.
In completed demo you haven’t any linked js and css files. And file connectorFRST2, which loads the form data is missed.
Your demo (after many local code editings is the next) are the next:


If load ONLY your form data to the form - you issue isn’t appear.

Hi, Darya,

Thanks, I thought I’d copied all the libraries my code is using into the ‘completed example’. Not sure why there are broken references.

I’ve written a stand-alone form with a Select field, which includes a selected:true option, copied exactly from one of the online DHTMLX demos. The selected:true part just doesn’t work. Not sure why, as it seems like it would be a very simple thing to implement.

Hi, Darya,

I got the selected:true code to work; it turns out it was the order of the DHTMLX JavaScript libraries which was the problem, solved by putting these libraries in this order:

<!-- Combo/select box -->
	<link rel="stylesheet" type="text/css" href="./dhtmlx/dhtmlxform/codebase/skins/dhtmlxform_dhx_skyblue.css">
	<script src="./dhtmlx/dhtmlxform/codebase/dhtmlxcommon.js"></script>
	<script src="./dhtmlx/dhtmlxform/codebase/dhtmlxform.js"></script>
	<script src="./dhtmlx/dhtmlxform/codebase/ext/dhtmlxform_item_combo.js"></script>
	<script src="./dhtmlx/dhtmlxCombo/codebase/dhtmlxcombo.js"></script>
	<script src="./dhtmlx/dhtmlxCombo/codebase/ext/dhtmlxcombo_extra.js"></script>
	<link rel="stylesheet" type="text/css" href="./dhtmlx/dhtmlxCombo/codebase/dhtmlxcombo.css">

Strangely, I already had each one of the libraries in my app code, just not in that particular order (I found the order in a DHTMLX combo box example).

Which raises another question: is there a specific order in which the libraries must be listed in the app code, please?

Thank you.

But now the form won’t add records … so obviously, the libraries must be kept in some specific order. I wonder if there is an order which would allow both the form to add records, and giive me selection defaults?

Aboul libararies: prog dhtmlxGrid musn’t be attached here.
About recommended order:

  1. dhtmlxcommon.js
  2. dhtmlxcontainer.js
  3. all the rest files
    When you include extensions - add them after main js file, i.e. 1-dhtmlxcombo.js, 2 - dhtmlxcombo_group.js

But now the form won’t add records …
How do you do this?

Hi, Darya, thanks for the information about the correct library order. I’ll re-order my libraries and see if that improves matters.

I add records via the datastore.add method, through the form:

myuid = (new Date()).valueOf(); 
myForm.setItemValue("ClientID", myuid);
obj = myForm.getFormData();
obj.id = myuid;
contacts.add(obj);

Thanks again!

Hi again, Darya,

All the libraries were already in the order you specified, so I guess that isn’t the problem.

Something very odd is going on … any other thoughts, please? Thanks.

Here is a working demo for you based on your provided code of the select:
13.02.01.rar (81.2 KB)

Thank you!

You are welcome!