This topic is locked

How to control form behaviour with field event

2/23/2020 7:31:44 PM
PHPRunner General questions
S
Smithy author

Hello everyone,

I am struggling to find a way to control behaviour on an add form.
I have a timesheet - if an employee has an open entry, I would like to display a message and prevent them from advancing any further, forcing them to click Back To List. If the employee doesn't have any open entries, then they proceed as normal.
I have attempted many variations using Javascript OnLoad etc. The closest I have come to is the below field event when the user scans their RFID card, however there is no messagebox displayed

this is the change field event on that cardid field:

function OnClient Before(params,ctrl,pageObj,ajax)

{
var ctrlemployeeid = ctrl.getPeer('employee_id');

params["employee_id_in"] = ctrlemployeeid.getValue();
} // function OnClient Before




function OnServer($params, $result)

{$result["employee_id_count"] = DBLookup("SELECT count(employee_id) FROM timesheet_entry WHERE employee_id = '" . $params['employee_id_in'] . "' AND finish_time is null");
} // function OnServer



This all works up to this point (at least, I don't get any errors - I can't get the result to echo / print on my page....)



function OnClient After(result,ctrl,pageObj,ajax)

{

var ctrlcarduida = ctrl.getPeer('card_uid');

var ctrlemployeeid = ctrl.getPeer('employee_id');

var ctrlwoseq = ctrl.getPeer('wo_seq');

var ctrlqty = ctrl.getPeer('qty_complete');
// rather than disabling all of these fields, disable the save button


if ($result["employee_id_count"] > 0)

{echo("How many timesheet entries has this employee got open ? ". $result['employee_id_count'])

ctrlcarduida.setDisabled();

ctrlemployeeid.setDisabled();

ctrlwoseq.setDisabled();

ctrlqty.setDisabled();

ctrlcarduida.setFocus();

return false;

}else{

ctrlcarduida.setEnabled();

ctrlemployeeid.setEnabled();

ctrlwoseq.setEnabled();

ctrlqty.setEnabled();
if (ctrlstartime.getValue() == '')

{ctrlstartime.setValue(now());

var ctrlwo = Runner.getControl(pageid, 'work_order');

ctrlwo.setFocus();}

}

} // function OnClient After


I am just at my wits end as to how to get a simple message to appear, or, at a minimum, see how to disable the save button on the form.
Any assistance is greatly appreciated.
Best regards,
Craig

S
Steve Seymour 2/24/2020

Maybe this page in the help could assist you....
https://xlinesoft.com/phprunner/docs/getitembutton(itemid_recordid).htm

S
Smithy author 2/24/2020



Maybe this page in the help could assist you....
https://xlinesoft.com/phprunner/docs/getitembutton(itemid_recordid).htm


Thank you for your reply halcyondaze.
I can disable the save button using the information from the link you provided - thank you for pointing me in the right direction.
Do you know if I can remove the 'disabled' status of a button using an if statement in a change field event ?

Using the Javascript OnLoad event only applies at the start of the process Ie: when the record is loaded. I would like to change the status based on a conditional check when the user changes from one field to another, if this is possible.
Thanks and regards,
Craig

S
Steve Seymour 2/25/2020



Thank you for your reply halcyondaze.
I can disable the save button using the information from the link you provided - thank you for pointing me in the right direction.
Do you know if I can remove the 'disabled' status of a button using an if statement in a change field event ?

Using the Javascript OnLoad event only applies at the start of the process Ie: when the record is loaded. I would like to change the status based on a conditional check when the user changes from one field to another, if this is possible.
Thanks and regards,
Craig


I'm sure you may be able to it with jQuery....
Have a look here...

https://asprunner.com/forums/topic/21685-enablingdisabling-a-standard-button/