views:

33

answers:

1

I have an .aspx hidden control that stores a defaultId for this dropdown. However, the values in the dropdown can change and sometime the defaultId is listed as one of the selections, other times it isn't. When the drop down clears we run this to reset it:

Global.getComponent("ddlVehicleType").setValue(Global.getComponent("DefaultVehicleTypeId").getValue());

Now when it sets that, if the dropdown doesn't have a value associated with that Id, it displays the actual Id in the field. I have a check for isNumeric now to see when that happens, but how do I make the field display the first value in the list of Id's it DOES have:

var displayedValue = Global.getComponent("ddlVehicleType").getRawValue();
            if (IsNumeric(displayedValue)) {

            }
A: 

Put together a unique little way of doing it, by going through the current populated store of that dropdown on the page:

var newId = 0;
var firstId = 0;
var typeStore = Global.getComponent("ddlVehicleType").getStore();
firstId = typeStore.getAt(0).get('LookupID');

typeStore.each(function(rec) {
    if (rec.get('LookupID') == Global.getComponent("DefaultVehicleTypeId").getValue())
    {
        newId = Global.getComponent("DefaultVehicleTypeId").getValue();
    }
});

if (newId != 0) {
    Global.getComponent("ddlVehicleType").setValue(newId);
} else {
    Global.getComponent("ddlVehicleType").setValue(firstId);
}
Scott