Autoload available data when data entering to form

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Autoload available data when data entering to form

Post by pbottcher » 2020-12-03 19:27

Hi,

yes you can. Attach a on "change" event handler to the selection box and if the necessary information is available, catch the data via ajax and fill the cases.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Autoload available data when data entering to form

Post by sathukorala » 2020-12-04 00:46

pböttcher wrote:
2020-12-03 19:27
Hi,

yes you can. Attach a on "change" event handler to the selection box and if the necessary information is available, catch the data via ajax and fill the cases.
Thanx pböttcher for the idea.
Can you help me a little bit with some elaboration....

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Autoload available data when data entering to form

Post by pbottcher » 2020-12-04 20:20

Hi,

can you be a bit more specific. Otherwise it is difficult to help further. What kind of dropdown do you have? What field do you need to fill? ....
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Autoload available data when data entering to form

Post by sathukorala » 2020-12-05 01:46

Thanks and here are the details
Attachments
epid.rar
(2.96 KiB) Downloaded 76 times
1.png
1.png (38.74 KiB) Viewed 1937 times
Last edited by sathukorala on 2020-12-05 01:49, edited 1 time in total.

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Autoload available data when data entering to form

Post by sathukorala » 2020-12-05 01:48

pböttcher wrote:
2020-12-04 20:20
Hi,

can you be a bit more specific. Otherwise it is difficult to help further. What kind of dropdown do you have? What field do you need to fill? ....
1.png
1.png (38.74 KiB) Viewed 1935 times
This is the actual page

I have attached the project file too

User selects 1 to 4 and they are all option lists with predefined values
COVID cases is a variable field and it should be loaded when all 1 to 4 are selected and if a record is available user should see the edit page instead of Save New button
Attachments
epid.rar
(2.96 KiB) Downloaded 77 times

sathukorala
AppGini Super Hero
AppGini Super Hero
Posts: 121
Joined: 2020-02-16 16:29

Re: Autoload available data when data entering to form

Post by sathukorala » 2020-12-05 11:57

I found a solution which works !!!

If above 4 dropdowns are selected and when the "Time Period" dropdown is clicked, AJAX call for the ajax.php with data parsing and if
any matches are found the user prompted to be redirected to the view/edit page

This goes in the hooks/table_name-dv.js

Code: Select all

$j('#time_period').on('click', function(){

		load_details();

});


function load_details(){

	if (($j('#time_period-container').select2('val') == '{empty_value}') || ($j('#province-container').select2('val') == '{empty_value}') || ($j('#district-container').select2('val') == '{empty_value}') || ($j('#hospital-container').select2('val') == '{empty_value}')){
		
		$j('#cases').val('');

	}else{

		time_value = $j('#time_period').val();
		province_value = $j('#province').val();
		district_value = $j('#district').val();
		hospital_value = $j('#hospital').val();

		$j.ajax({
			url: 'hooks/ajax.php',
			data: { time_column : time_value , province_column : province_value , district_column : district_value , hospital_column : hospital_value},
			success: function(data){
				if (!$j.trim(data)) {
					$j('#cases').val('');
				}else{
					alert ("Record Exists !!! Click OK to redirect to the record view page (If you have permission you can edit)");
					window.location = "COVID_cases_view.php?SelectedID="+data;
				}
			}
		});

	}
}
This goes in the hooks/ajax.php

Code: Select all

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


	$time = makesafe($_REQUEST['time_column']);
	$province = makesafe($_REQUEST['province_column']);
	$district = makesafe($_REQUEST['district_column']);
	$hospital = makesafe($_REQUEST['hospital_column']);


	$sql = "SELECT id FROM covid_cases WHERE time_period = '{$time}' AND province = '{$province}' AND district = '{$district}' AND hospital = '{$hospital}'";

	$data = sqlValue($sql);

	echo $data;
?>
Experts comment and refine the code

Post Reply