Set value based upon data in other field

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
User avatar
shasta59
AppGini Super Hero
AppGini Super Hero
Posts: 231
Joined: 2013-01-08 19:40
Location: Calgary, Alberta, Canada

Set value based upon data in other field

Post by shasta59 » 2015-05-30 22:24

Using 5.31 (have not upgraded yet)

If you wish to set the value of a form field based upon the value put in another field here is one way to do it.

I recommend you use a field with set values to pick from to make it easier. My example uses a field where the values are Yes and No. The file you modify is the tablename_templateDV.html. I have done this using jquery.

At the very bottom you would add text similar to the following using your values.

Code: Select all

<script>
	
	$j(document).ready(function(){
	$j('#position').change(function(){
	
	var positionvalue = ($j('#position').val());
	if(!positionvalue || positionvalue == 'Yes'){
	$j('#points').val("2");
	}else{
	$j('#points').val("1");
	}
	});
	});
	</script>
Explanation:

<script> this line announces what follows is a script
$j(document).ready(function(){ - this is the jquery document ready function
$j('#position').change(function(){ - this line watches for the field to change
var positionvalue = ($j('#position').val()); - this line put the value of the field called postion into the variable positionvalue - gets content of field
if(!positionvalue || positionvalue == 'Yes'){ - this line is the start of the if function. Tests to see if the variable postionvalue equals Yes
$j('#points').val("2"); - if yes it puts in a 2 into the field called points.

Then next line then puts in a 1 if it is not equal to yes using the if then else construct.

</script> - closes the script section.

You may wish to turn off the ability to edit the field so the user cannot change the input but you can put a value in. I have another topic which covers how to do that. (Not sure which one right now).

There is a tighter way to do it but this method is fairly easy to follow and allow everyone to make easy changes to suit their needs.

Enjoy

Alan
Calgary, Alberta, Canada - Using Appgini 5.50 -

jstrick
Posts: 13
Joined: 2013-03-04 20:55

Re: Set value based upon data in other field

Post by jstrick » 2016-05-12 22:10

ok Alan

question in the above statement it says:

At the very bottom you would add text similar to the following using your values.

the question is at the bottom of what?
I have tried building a magic file and no luck.
Tried to add it to the bottom of a hook file no luck.

So were the heck do i add this or something like it.

Thanks in advance
using version 5.5

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Set value based upon data in other field

Post by AhmedBR » 2016-05-12 22:42

jstrick,

The file to be modified is not the hook file, it is tablename_templateDV.htm
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

jstrick
Posts: 13
Joined: 2013-03-04 20:55

Re: Set value based upon data in other field

Post by jstrick » 2016-07-08 01:16

Well maybe so but this worked in side the hooks folder

function Your table name_before_update(&$data, $memberInfo, &$args){
if($data['field with data name you want looked at'] == 'Complete'){ $data['field to change staus of'] = "null" and $data['another field you want changed to a specific date'] = date('Y-m-d'); }
return TRUE;
}


Think I explained this correctly seems easier in a hook took a bit to figure out found this on the forum some place.

Seems like you start making changes outside of the hook folder things get complicated.

Post Reply