jquery and ajax for autofill

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
User avatar
D Oliveira
Veteran Member
Posts: 51
Joined: 2018-03-04 09:30

jquery and ajax for autofill

Post by D Oliveira » 2018-03-22 20:10

any suggetions of why is it not working?

gutterwb-dv.js

Code: Select all

$j(function(){

	
	/* on changing product, retrieve unit price from products table and populate unit price field */
	$j('#gEstimateID').on('change', function(){

		var pid = $j('#gEstimateID').val();
		
		if (pid == ''){

			$j('#gename').val('');
			$j('#geaddress').val('');
			$j('#gephone').val('');
			$j('#geemail').val('');
			$j('#gegatecode').val('');
			$j('#gesubdv').val('');
			$j('#geprice').val('');
			$j('#geestmname').val('');
			$j('#geestmdate').val('');
			$j('#gecomment').val('');


		}else{

			var pid = $j('#gEstimateID').val();

			$j.ajax({
				url: 'hooks/ajax-gutterajax.php',
				data: { pid: pid },
				success: function(data){
					$j('#gename').val('data[1]');
					$j('#geaddress').val('data[2]');
					$j('#gephone').val('data[3]');
					$j('#geemail').val('data[4]');
					$j('#gegatecode').val('data[5]');
					$j('#gesubdv').val('data[6]');
					$j('#geprice').val('data[7]');
					$j('#geestmname').val('data[8]');
					$j('#geestmdate').val('data[9]');
					$j('#gecomment').val('data[10]');
				}
			});

		}


	});
	

});
hooks/ajax-gutterajax.php

Code: Select all

<?php
	$currDir = dirname(__FILE__) . '/..';
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

$pid = $_REQUEST['pid'];

$data[1] = sql("SELECT name FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[2] = sql("SELECT address FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[3] = sql("SELECT phone FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[4] = sql("SELECT email FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[5] = sql("SELECT gatecode FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[6] = sql("SELECT subdv FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[7] = sql("SELECT price FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[8] = sql("SELECT estmname FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[9] = sql("SELECT estamdate FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);
$data[10] = sql("SELECT comment FROM EstimatesHO WHERE EstimateID = '{$pid}'", $eo);

echo $data;

?>

User avatar
D Oliveira
Veteran Member
Posts: 51
Joined: 2018-03-04 09:30

Re: jquery and ajax for autofill

Post by D Oliveira » 2018-03-23 14:20

not the most efficient but I got it to work, the gEstimate field is a lookup orginally made from appgini, and the following fields are lookups dealt with jquery, enjoy :)

gutterwb-dv.js

Code: Select all

$j('#gEstimateID-container').on('click', function(){

		update_order_total();

});


function update_order_total(){

	if ($j('#gEstimateID-container').select2('val') == '{empty_value}'){
		
		$j('#gename').val('');

		$j('#geaddress').val('');
				
		$j('#gephone').val('');
	
		$j('#geemail').val('');
	
		$j('#gegatecode').val('');
	
		$j('#gesubdv').val('');
	
		$j('#geprice').val('');
	
		$j('#geestmname').val('');
		
		$j('#geestmdate').val('');
		
		$j('#gecomment').val('');

	}else{

		valor_entidad = $j('#gEstimateID').val();

		$j.ajax({
			url: 'hooks/ajax-est.php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#gename').val(data);
				}else{
					$j('#gename').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(1).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#geaddress').val(data);
				}else{
					$j('#geadress').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(2).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#gephone').val(data);
				}else{
					$j('#gephone').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(3).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#geemail').val(data);
				}else{
					$j('#geemail').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(4).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#gegatecode').val(data);
				}else{
					$j('#gegatecode').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(5).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#gesubdv').val(data);
				}else{
					$j('#gesubdv').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(6).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#geprice').val(data);
				}else{
					$j('#geprice').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(7).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#geestmname').val(data);
				}else{
					$j('#geestmname').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(8).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#geestmdate').val(data);
				}else{
					$j('#geestmdate').val('');
				}
			}
		});
		$j.ajax({
			url: 'hooks/ajax-est(9).php',
			data: { entidad_id: valor_entidad },
			success: function(data){
				if (data) {
					$j('#gecomment').val(data);
				}else{
					$j('#gecomment').val('');
				}
			}
		});

	}
}
hooks/ajax-est.php

Code: Select all

<?php
	$currDir = dirname(__FILE__) . '/..';
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

	/* grant access to all users who have acess to the orders table */
	$od_from = get_sql_from('EstimatesHO');
	if(!$od_from){
		header('HTTP/1.0 401 Unauthorized');
		exit;
	}

	$entidad = makesafe($_REQUEST['entidad_id']);


	$sql = "SELECT nameFROM EstimatesHO WHERE EstimateID = '{$entidad}'";

	$datos = sqlValue($sql);

	echo $datos;
hooks/ajax-est(1)

Code: Select all

<?php
	$currDir = dirname(__FILE__) . '/..';
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");

	/* grant access to all users who have acess to the orders table */
	$od_from = get_sql_from('EstimatesHO');
	if(!$od_from){
		header('HTTP/1.0 401 Unauthorized');
		exit;
	}

	$entidad = makesafe($_REQUEST['entidad_id']);


	$sql = "SELECT address FROM EstimatesHO WHERE EstimateID = '{$entidad}'";

	$datos = sqlValue($sql);

	echo $datos;
the following ajax files just have to change the field after SELECT, thats it

Post Reply