This topic is locked
[SOLVED]

Highlight fields that are mandatory but empty

1/8/2025 3:24:22 PM
PHPRunner General questions
A
asawyer13 authorDevClub member

I see JS code in this part of the help Right Here
that will hightlight empty fields

Rather than manually having to enter the code for all fields, is there a way to iterate thru all the in JS so it doesn't have to be hard coded and so much code?

Thanks
Alan

C
cristi 1/10/2025

There is a way - from the manual example 1 - you can see there how to iterate validation through all controls: https://xlinesoft.com/phprunner/docs/ctrl_addvalidation.htm

Sergey Kornilov admin 1/10/2025

Here is the code you can use in Javascript OnLoad event of Add/Edit pages. Tested in version 11. Make sure to update the table name accordingly.

var recCtrlsArr = Runner.controls.ControlManager.getAt('employees');
// loop through all controls on the page to see if they are
for(var i=0;i<recCtrlsArr.length;i++)
{
var ctrl1 = recCtrlsArr[i];
var c = ctrl1.getDispElem();
if (c.parent().parent().parent().attr('data-required')=='true') {

// set click handler
ctrl1.on('click', function() {
if (!this.getValue())
this.addStyle('background: yellow;');
else
this.addStyle('background: white;');
});

// key up handler
ctrl1.on('keyup', function() {

if (!this.getValue())
this.addStyle('background: yellow;');
else
this.addStyle('background: white;');
});

// set the back ground initially
if (!ctrl1.getValue())
ctrl1.addStyle('background: yellow;');
else
ctrl1.addStyle('background: white;');
}
}