Set Default Value to a Combo box, when data is taken from a Store - combobox

In Dojo I want to set the first/top option of may Store as the default/displaying option/text of the combo box. I went through the documentation to found no help. if anyone have done that before please share your opinion.
Ps - I can't use ID or name of the option to set it. I want to display what ever the data item somes first in the store to display.
Thanks in advance.
and this is how my combo-box looks like
var Selectbox = new dijit.form.ComboBox({
id: "box1",
disabled:true,
uppercase:true,
autoComplete:false,
trim:true,
value: "boxvalue",
store:detailDataStore,
style:"width:120px; color:black;"
}).placeAt(topContentPane10.containerNode);

There isn't a magic property to set the combobox default selection from a store, you'll have to set it manually.
Something like this:
box.set('value',store.data[0].value)
See this fiddle: http://jsfiddle.net/Gkbpb/1/

Related

why the combo box displays the objects?

I have a combobox which I would like to populate with some info. Below is the code:
cmbSelectProject.Items.Clear();
cmbSelectProject.ValueMember = "Sid";
cmbSelectProject.DisplayMember = "Name";
cmbSelectProject.DataSource = new BindingSource(ApiCaller.LstProjects, null);
So, there is a class Project with the existing properties "Sid" and "Name". ApiCaller.LstProjects call returns a list of Projects. So I expect the "Name" to de displayed and "Sid" is used as value.. Instead I see the bunch of Project objects displayed in the dropdown.
What am I doing wrong in here? Thanks for the suggestions.
Try This sequence.
Set DataSource property.
Set ValueMamber and DisplayMember.
Refresh Combo. using Refresh() method.

Unable to bind the id of the combobox field on grid update

I'm trying update the grid with the edited values. When I update the bus type and give update, the binded value in the back end is valueFied that's the id, But when I update only time and name the bus type cell renders the displayField which fails the gridupdate at the back end saying Integer value error, since the display field is the string , How would i always render or bind the valuefield to the back end no matter what i update and display always the type name,
here's the fiddle to try.Fiddle
Hoping for a quick response.
Screen Shot of the grid
Thanks much.
I Solved this issue by adding below method in the update function.
if(!Ext.isNumber(gridRow.data.typebus))
{
gridRow.data.typebus = gridRow.data.id;
};
hope this helps someone.

Initializing ngModel with data - AngularJS Bootstrap bs-select

I am maintaining a site that allows users to create a profile of sorts that will allow them to broadcast activities to a feed. I implement ng-grid to keep track of all the profiles that are created, and have created two buttons that allow users to create/edit these profiles. My only problem right now is, when users select a row on the grid and attempt to edit that specific row, the drop-down menu is not auto-populated with the data from ngModel.
This is the part of the form I am having trouble with:
<select ng-model="source.canSendTo" ng-options="value.name for value in sourceCanSendTo" data-style="btn" bs-select></select>
And within the controller, I have sourceCanSendTo defined as:
$scope.sourceCanSendTo = [ {"id":"abc", "name": "ABC"}, {"id":bcd", "name": "BCD"} ... ];
On row selection, I simply set source = the selected item, and console.logs show that all the data is there. The other parts of the form are being populated properly (mainly s), and console.log($scope.source.canSendTo) shows that the original data is there, it's just that select is defaulted to being blank...how would I go about trying to pre-select certain elements on the drop-down select I currently have?
For example, if the profile has 'abc', 'bcd' selected, how can I make it so that when I edit that profile, the drop down box shows 'abc,bcd' instead of just "Nothing Selected"?
Edit: I previously responded to a comment inquiring about bs-select, saying that it simply controlled some CSS elements of the drop down box - seems like this is completely incorrect after a quick google search when everything else led to dead ends. Does anyone have any idea how to properly initialize the model with data so that when I preload my form, the 'can send to' drop down select actually has the selected options selected, as opposed to saying "Nothing Selected"? Thanks in advance for all help!
As you are binding source.canSendTo to the name (value.name) of sourceCanSendTo then you just need to initially have an structure binding the names which had been saved, something like this:
source.canSendTo = ['abc', 'bcd']; //And all the selected values
So you need to construct your source.canSendTo property to this structure.
PS: If you show how you bring your data from the server, I can help you to construct the source.canSendTo property.
$scope.canSendTo must be initialized with a reference to the selected option.
var initialSelection = 0;
$scope.source = { canSendTo : [ {"id":"abc", "name": "ABC"}, {"id":bcd", "name": "BCD"} ... ] };
$scope.canSendTo = $scope.source.canSendTo[initialSelection];
Finally found out what was wrong with my code - seems like the data being stored in the model wasn't the same as what was in ngOptions, played around a bit with ngOptions and managed to get something that works. Working snippet of code:
<select ng-model="sendTo.name" ng-option="value.name as value.name for value in sourceCanSendTo" data-style="btn" multiple bs-select>
(Realized that the variable being used for ngModel was a fairly ambiguous in terms of naming convention, changed it)

How to programmatically open dojox mobile combobox

I'm using a dojox/mobile/ComboBox widget and would like to programmatically open it.
Tried to use require("dijit/registry").byId("").openDropDown();
but the source comment says... "To be called only when this.dropDown has been created and is ready to display (that is, its data is loaded).", which it doesn't seem to be :(
Calling the _onClick doesn't help either.
Any assistance would be highly appreciated.
Guy
I had the same issue as you.
The dojox.mobile.ComboBox was causing the android keyboard to display.
My work around was to create the combobox programmatically like this:
var myCombo = new ComboBox({
store: registry.byId('your data list'),
value: ''
},"theDomInput");
myCombo.startup();
then in my index.html I had a field with the readonly set like this:
<input id="theDomInput" type="text" readonly/>
The startup function needs to be called before the click event of the combobox.
This works for me. Let me know if you come up with something better.

Saving a Disabled field

In my edit.ctp I have a select box which I don't need the user to change. So I put array(disabled=>true). But this field is not coming when
pr($this->data); and showing an error while saving.
What options are there to solve this issue.
If you know the value of the data you can edit it at the controller.
$this->request->data['ModelName']['fieldName'] = value;
UPDATE
Edit it like
echo $this->Form->input('patient_id',array('type'=>'select', 'readonly' => 'readonly'));
You could make the field readonly so that user cant change it , or use some hidden field to post the data that you want, or you could use some css, like visibility:hidden, so that user dont see it but it'll be posted.
echo this->Form->input('patient_id',array('type'=>'hidden'));
You can use some other name for the input and check in controller, or you could completely remove the select element from the view*strong text* (since, its not needed as user dont need to change it)

Resources