I'm trying to retrieve the text entered in the bootbox.prompt. The prompt comes up fine but I get no value because it doesn't wait for the value to be entered.
The context of it's use: when a specific selection is made from a dropdown, a certain field value is required. I could popup a message saying its required and put the focus on that field, but I'd rather get the value from the popup and populate the field (ie this prompt).
//trigger
@Html.DropDownListFor(m => m.ShipmentTypeID, ViewBag.ShipmentTypes as IEnumerable<SelectListItem>, new { @class = "form-control", required = "required", onchange = "checkShipmentType();" })
//trigger action checkShipmentType() includes
switch($("#ShipmentTypeID").val()){
case 'somevalue':
var responseVal = promptEntry("Please enter the Originating Order");
$("#OriginatingOrder").val(responseVal);
break;
}
//in jquery myLibrary ...
function promptEntry(message) {
try {
var prompt = bootbox.prompt({
title: '<i class="far fa-keyboard"></i> ' + (typeof message === "undefined" ? "Entry Required" : message),
centerVertical: true,
callback: function (result) {
console.log(result);
}
})
.find('.modal-header').css({ 'background-color': '#3db9bf', 'font-weight': 'bold', 'border-color': '#3db9bf', color: '#8a6d3b', 'font-size': '2em' });
} catch (err) {
alert(err);
}
}
I figured out how to get it to do what I wanted, even though I don't like how it works. The callback routine is what activates when something is entered or a button is pressed. I could not get it to return a value, so I did what I need to do inside the callback routine.
My goal was to populate a textbox value with the entered value. So I sent in the 'name' of the object and populated the $(obj).val() with the result.
}