开发者

Setting dropdown to first value

开发者 https://www.devze.com 2023-01-20 11:29 出处:网络
I have an .aspx hidden control that stores a defaultId for this dropdown. However, the values in开发者_StackOverflow the dropdown can change and sometime the defaultId is listed as one of the selectio

I have an .aspx hidden control that stores a defaultId for this dropdown. However, the values in开发者_StackOverflow 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)) {

            }


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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消