Get KoolPHP UI with 30% OFF!

calling a php function that echos a java function within a custom validator does not works.

Abraham
hi theree.. i have this php fuction wich calls the alert java function..:
function alert($msg){
	echo "<script type='text/javascript'>alert('$msg');</script>";
}

if i call it in any place in my php code it works..
but if i call it inside a customValidator then it wont work.
why is this happening??.
this is my column and his validator:
Spoiler content
Posted Sep 3, 2015 , edited Sep 3, 2015 Kool
David
Hi Abraham,
I think you didn't put the alert javascript function inside a script tag. Anyway, it's advisable to just return the error message and let KoolGrid shows it for you.
Rgds,
Posted Sep 4, 2015 Kool
Abraham
Hi there David.
The alert on this section:
		if($value>$xAmortizar){
			alert("La suma de las Amortizaciones no debe exeder los Anticipos");
			return null;
		}

is actualy a php functions that hanldes the string msg and pass it to a java script calling the alert..
.. the reason i wont let the validator to return the msg is that this is just a Warning validator not an on error stop inserting...
.. seems that ajaxs has somthing to do with this issue..
still traing to figre it out.
i can allways set a $_Session variable and catch it on OnConfirmInsert event to send the Warning alert.. but... you know.. i wannt to code preaty lol.
Posted Sep 7, 2015 Kool
Abraham
well this is my work arround..
my validator:
	function validaAmortizacion(&$value){
		$value = str_replace(",","",str_replace("$","",$value));
		$xAmortizar = $_SESSION[basename($_SERVER['PHP_SELF'])."txtxAmortizar"];
		if(isset($_SESSION["xAmortizarOnEdit"])){
			$xAmortizar=$_SESSION["xAmortizarOnEdit"];
		}		
		if($value>$xAmortizar){
			setcookie("alertAmortizacion", "1"); // this is the cookie that will trigger the alert on the js event handler.
	     }
		unset($GLOBALS[_SESSION]["xAmortizarOnEdit"]);
	        return null;//returns null causes this validator is just a warning validator..
	}

add the event handler function to the grid..
$grid->ClientSettings->ClientEvents["OnGridCommit"] = "Handle_OnGridCommit";

then in js Handle_OnGridCommit
	function Handle_OnGridCommit(sender,args){
		var alertAmortizacion = getCookie("alertAmortizacion");//get the cookie value;
		if(alertAmortizacion=="1"){
			clearCookie("alertAmortizacion");//clear the cookie so it dies.
			alert("La suma de las Amortizaciones no deberia exceder los anticipos!!");
		}
	}
Posted Sep 8, 2015 Kool