This topic is locked
[SOLVED]

Dropdown list event

1/9/2024 11:40:05 AM
PHPRunner General questions
M
MikeUk author

Hi everyone, my first post.

I have an issue where I have two combo boxes on a form.
The first one is quite simple, it builds afairl;y complext query that performs some calculations, so it's not an option to use the lookup table options as the table has values are calculated by the first combo,

Depending on the result from the first combo, it then selects the correct itemId in the second combo box.

I have a 'changed' event on the second dropdows (which I have tested manually).

The change event on the second combo boxes (named: ctlPriceTable) , retrives the appropriate record from it table, and fill in other fields on the form.

The problem whenthe ID is set on the second combo, the 'changed' event does not fire.

Any ideas how to solve this?

This is the after event from the first combobox.

if (result['id'] > 0 ) {
var ctlPriceTable = ctrl.getPeer('pricetable');
ctlPriceTable.setValue(result["id"]);
}

Thisworks and sets the value, but does not trigger the change event for the second combo so the fields are blank.

I tried adding a blur event and doing this;

if (result['id'] > 0 ) {
var ctlPriceTable = ctrl.getPeer('pricetable');
ctlPriceTable.setValue(result["id"]);
ctlPriceTable.setFocus;
}
nextControl.sefFocus;

But that didn't trigger either.

M
MikeUk author 1/9/2024
nextControl.sefFocus;

Ignore the typo ..

It is setFocus

C
cristi 1/9/2024
  • ctrl.getPeer works in inline mode - are you using inline mode?
  • JS errors are visible in browser console - for Firefox fire up the web developer tools and look in Console tab - do you see any error there?
  • if you use a tri part event you should post all code - maybe the error is not where you think it is...
  • setFocus is a method so write it accordingly with ()

M
MikeUk author 1/9/2024

Hi Cristi

Part 1. ctlFailureModeChange
Thanks for your reply. It's in a tri-part event.
This is for the code that sets the combo - which works. I will post the second combo seperartely
No JS Errors.

//Before client


var ctlMediaType = Runner.getControl(pageid, 'mediatype');
var ctlMediaSize = Runner.getControl(pageid, 'mediasize');
var ctlMediaSizeType = Runner.getControl(pageid, 'sizetype');
var ctlAgentID = Runner.getControl(pageid, 'agentid');
var ctlFailureMode = Runner.getControl(pageid,'failuremode');
// get values
var varMediaSize = parseFloat(ctlMediaSize.getValue());
var varMediaSizeType = parseFloat(ctlMediaSizeType.getValue());
// set parameters
params["failuremode"] = ctlFailureMode.getValue();
params["mediatype"] = ctlMediaType.getValue();
params["sizetype"] = ctlMediaSizeType.getValue();
params["mediasize"] = ctlMediaSize.getValue();
params["agentid"] = ctlAgentID.getValue();
params["realsize"] = varMediaSize * Math.pow(1000, varMediaSizeType);

// end

//Server


$qryType = "SELECT";
$fields = "id";
$table = "quotepricetable";
$qryWhere = "WHERE agentid = '" . $params['agentid'] . "' ";
$qryWhere .= "AND '" . $params['realsize'] . "' >= realsizefrom ";
$qryWhere .= "AND '" . $params['realsize'] . "' <= realsizeto ";
$qryWhere .= "AND basefault = '" . $params['failuremode'] . "' ";
$qryWhere .= "AND active = '1' ";
$qry = DB::PrepareSQL("$qryType $fields FROM $table $qryWhere");
$rs = DB::Query($qry); // run the query
// Load data into record set array ($rs)
$data = $rs->fetchAssoc(); // store data into an array - $result
if ($data) {
$result["id"] = $data["id"];
}
else{
$result["id"] = 0;
}
//end

//after client


var ctlLookupFailure = ctrl.getPeer['lookupfailure'];
if (result['id'] > 0 ) {
var ctlPriceTable = ctrl.getPeer('pricetable');
ctlPriceTable.setFocus;
ctlPriceTable.setValue(result["id"]);
}
else {
var errMessage = "There are no matching price tables for this media \n\n";
errMessage += "Make sure you have selected the correct Agent, if so .. \n\n";
errMessage += "1. Select a a different table option and make edits manually\n\n";
errMessage += "2. Add a new price table for this media and fault (recommended)\n";
swal("Warning",errMessage,"warning");
}


M
MikeUk author 1/9/2024

Part 2. The second combo - ctlPriceTable value is set by
ctlPriceTable.setValue(result["id"]); above

//Before client

// Select price table
var ctlPriceTable = Runner.getControl(pageid,'pricetable');
var priceTableId = ctlPriceTable.getValue();
params["value"] = PriceTableId
if (priceTableId == 0 || priceTableId == '') {
return false;
}

//Server

// Build query and execute //

$qryType = "SELECT";
$fields ="*";
$table = "quotepricetable";
$qryWhere = "WHERE ";
$qryWhere .= "id = '" . $params['value'] . "' ";
$qryWhere .= "AND active = '1' ";

$qry = DB::PrepareSQL("$qryType $fields FROM $table $qryWhere");
$rs = DB::Query($qry); // run the query

// Load data into record set array ($rs)
$data = $rs->fetchAssoc(); // store data into an array - $result

if ($data) {
$result['inceco'] = $data["ecoactive"];
$result['incstd'] = $data["stdactive"];
$result['incemg'] = $data["emgactive"];
$result['ecotime'] = $data["timeeco"];
$result['stdtime'] = $data["timeStd"];
$result['emgtime'] = $data["timemg"];
$result['ecocost'] = $data["priceeco"];
$result['stdcost'] = $data["priceStd"];
$result['emgcost'] = $data["priceEmg"];
$result ['isdata'] = true;
} else {
$result['isdata'] = false;
}

//client after

//Client After
if (result["isdata"]) {
// get controls
var ctlIncEco = ctrl.getPeer('inceco');
var ctlIncStd = ctrl.getPeer('incstd');
var ctlIncEmg = ctrl.getPeer('incemg');

var ctlTimeEco = ctrl.getPeer("ecotime");
var ctlTimeStd = ctrl.getPeer('stdtime');
var ctlTimeEmg = ctrl.getPeer('emgtime');

var ctlCostEco = ctrl.getPeer('ecocost');
var ctlCostStd = ctrl.getPeer('stdcost');
var ctlCostEmg = ctrl.getPeer('emgcost');

//eco
ctlIncEco.setValue(result["inceco"]);
if (result["inceco"] == 1) {
ctlCostEco.setValue(result["ecocost"]);
ctlTimeEco.setValue(result["ecotime"]);
} else {
ctlCostEco.setValue('');
ctlTimeEco.setValue('');
}

//std
ctlIncStd.setValue(result["incstd"]);
if (result["incstd"] == 1) {
ctlCostStd.setValue(result["stdcost"]);
ctlTimeStd.setValue(result["stdtime"]);
} else {
ctlCostStd.setValue('');
ctlTimeStd.setValue('');
}

//emg
ctlIncEmg.setValue(result["incemg"]);
if (result["incemg"] == 1) {
ctlCostEmg.setValue(result["emgcost"]);
ctlTimeEmg.setValue(result["emgtime"]);
} else {
ctlCostEmg.setValue('');
ctlTimeEmg.setValue('');
}
}
else{ // clear fields of any old data
ctlCostEco.setValue('');
ctlTimeEco.setValue('');
ctlCostStd.setValue('');
ctlTimeStd.setValue('');
ctlCostEmg.setValue('');
ctlTimeEmg.setValue('');
ctlIncEco.setValue('');
ctlIncStd.setValue('');
ctlIncEmg.setValue('');
}

This event works fine, it the selection is made directly from the combo box. However the customer want's it to select the correct value, to avoid errors. They need other options showing in the list, but want a default.

I thought about setting a button 'Get prices' but the tri part does not seem to accept, getPeer as that drop a JS bomb.

M
MikeUk author 1/9/2024

I spotted this typo

// Select price table
var ctlPriceTable = Runner.getControl(pageid,'pricetable');
var priceTableId = ctlPriceTable.getValue();
params["value"] = PriceTableId // < ----------------
if (priceTableId == 0 || priceTableId == '') {
return false;
}

I fixed it but it made no difference.

M
MikeUk author 1/11/2024

So, is this possible?

So far it has raised 3 problems that I'm trying to work around.
Is there a way to invoke a change event on the control? My workingwas based on the understanding that changing the value would fire the event.
It seems it's the same with other types of controls too.

I have to do a subtotal, vat and final total using an edit and change event, they dont fire either when the cobobox is changed.

M
MikeUk author 1/12/2024

Ok I fixed this using a custom button;

Using a slightly modified version of Corries example

$("a[id=New_Button_" + pageid + "]").click()

The code below works the same, and involves a little less typing.

$("a[id*='New_Button_']").click();

Then, I moved the code from the original control to the button tri-part( changing the getPeer to Runner.getControl(pageid,'ctrl'); )

Now when I make a change to the first field, I use the click event on the button to populate the fields and it works!

I also altered the change_event on the second dropdown, to click the button.
So managed to resolve this, without duplicating the code.