same address

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
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

same address

Post by baudwalker » 2018-04-26 05:21

Hi All,

I have two tables, 'customer' and 'job'.

In 'job' there is two different addresses. One is the postal address, this is auto filled from the customer table. The second is the job address. These can both addresses be the same or sometimes different.

The user would input the job address or I could have an autofill as for the postal address, but how can I have both.

in other words have autofill without read only text fields so the user can overwrite the autofill information

Thank you in advance

Barry

R Tammam
Veteran Member
Posts: 113
Joined: 2017-08-26 15:35

Re: same address

Post by R Tammam » 2018-04-30 00:56

Hello baudwalker,

i think you should make a text field so the user will have the right to fill it , and inject a button beside call it copy postal address
the copy postal address will simply copy the auto filled value of postal value and paste it in the text field
i hope that this idea would help you

Regards,
Reham

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: same address

Post by baudwalker » 2018-05-09 23:51

Hi Reham,

I see what you mean but it is not want I really require.

I have the postal address of the customer in the 'customer table'. Sometimes the job address is the same as the postal address so I would have the postal address loaded as the job address in the 'job table'. Other times the job address is different to the postal address so the user can enter the correct job address.

As it is now when I use autofill the resulting textbox is read only.

I have gone over Section10 Lecture 26 of the Appgini tutorials on udemy.com and just can't get it to work with multiple textboxes (address, town, postcode) triggered by a checkbox

Barry

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

Re: same address

Post by pbottcher » 2018-05-11 10:11

Hi,

I would suggest that you put you addresses in a separate table and reference in your customer table, postal address one address and in your job table, job address either the same entry in the address table, or a different entry if they do not match.

regards
Pascal
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.

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: same address

Post by baudwalker » 2018-05-12 00:15

Thank you Pascal,

I don't think that would work in my instance.

What is done now is that the user starts with the customer table. Either by selecting the customer or creating a new one. Then the job table icon is selected from the right hand menu. This preloads the customer's name and address into the job table. These customer details are also used for invoicing. In most cases the job address is the same as the customer's address. I could just load the customer details into the job address. But for those jobs that are at a different location from the customer's address I need to be able to input the new address.


I believe the best way, in this instance, would be to start with blank text boxes for the address and have a check box to load the address from the customer table if required.


As I mentioned above I see that Section10 Lecture 26 of the Appgini tutorials on udemy.com and just can't get it to work with multiple textboxes and it is the opposite to above.

I found, somewhere in this forum, a Jquery function to hide certain textboxes when the checkbox is checked. All I require is to input my information into the textbox instead of hiding them.


I hope I have not muddied the waters

Barry

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: same address

Post by baudwalker » 2018-05-12 08:32

I have the basis working with the following code. this will insert the words 'address' and 'town' in the appropriate textboxes

Code: Select all

jQuery(function(){
    jQuery('#same_add').click(function(){
         if(jQuery(this).prop('checked')){
             
              jQuery('#job_address').val('address');
             jQuery('#job_town').val('town');
         }else{
          
             jQuery('#job_address').val('');
             jQuery('#job_town').val('');
         }
    });
});
One of the fields I now wish to copy is an autofill lookup field. The AppGini code for that field follows...

Code: Select all

<div class="form-control-static" id="address">15 My Home Address &nbsp;</div>
This field does not have a 'value' therefore the following code will not work

Code: Select all

 jQuery('#address').val();
In the database the feild is and the 'customer' table and the column is 'cust_address'


Barry

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

Re: same address

Post by pbottcher » 2018-05-12 21:13

Hi Barry,

sorry, but I'm a little bit confused on which data you will hold in which table.
As far as I understand, you have a customer table that has a column 'cust_address'. What about the 'town' and 'address' fields in the job table?
Or are you using in the customer table 'cust_address' and 'cust_town' which may or may not be reflected in the job table in fields like 'job_address' and 'job_town' depending if they should be the same or not.

Also do you have a checkbox through appGini to identify if the job will use the same address (it looks like in your code above, but do you need it).

I could suggest you that you can handle this via the hooks/<tablename>-dv.js file (I assumed that there is one address field)

Code: Select all

$j(function () {
	var clear_address = function () {
		if (this.checked) {
			$j('#job_address' ).val("");
		}
		else {
			check_address();
		}
	}
	var check_address = function (v_customer="") {	
	if (v_customer == "") v_customer=$j('#customer' ).val();
	if (v_customer != "") {
		$j.ajax({
				async: false,
				url: 'hooks/ajax-get_cust_addr.php?cust=' + (v_customer),
				type: 'get',
				cache: false,
				success: function (data) {  
					$j('#job_address' ).val(data.toString().trim());
				},
			});	
			if ( $j("#myCheckbox").length ==0 ) {
				$j("#job_address").after('<input type="checkbox" id="myCheckbox" name="myCheckbox" > Use different address</input> ');
				$j("#myCheckbox").on('change', clear_address);
			}
			else $j("#myCheckbox").prop('checked', false);
		}
	}
	// need to wait till the ajax request completed
	$j( document ).ajaxComplete(function( event, xhr, settings ) {
		if ( settings.url.substring(0, 14) === "ajax_combo.php" ) {
			var v_left = settings.url.indexOf("=")+1;
			var v_right = settings.url.indexOf("&");
			var v_id = settings.url.substring(v_left,v_right);
			if (v_id != "") {
				check_address(v_id);
				$j(event.currentTarget).unbind('ajaxComplete');
			}
		}
		
	});
 
	var v_cust=$j('#customer').val();
	
	if (v_cust != "") {
		check_address();
	}	

	$j("#job_address").on('change', clear_address);

	$j('#customer' ).on('change', check_address);

});
and the 'hooks/ajax-get_cust_addr.php' file to retrieve the address of the selected customer.

Code: Select all

<?php
	$currDir = dirname(__FILE__);
	include("../language.php");
	include("../lib.php");
	
//	restrict_access if needed 
	$customer = $_REQUEST['cust'];
	$address = sqlvalue("SELECT `customer`.`cust_address` FROM `customer` WHERE `ID`=".$customer);	
	echo $address;
You would need to adjust the different tags to match your project and the SQL to match your DB. Also, if you have multiple entries for the address like town, address etc, you would need to adjust the ajax and the SQL to reflect your needs.

If you go with your solution you need to wait till the ajax to fill the auto-fill is completed.

You can try

$j('#address' ).text();

instead of the val.

like jQuery('#job_address').val( jQuery('#address').text());

regards
Pascal
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.

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: same address

Post by baudwalker » 2018-05-13 23:35

In the customer table the required columns are cust_address and cust_town. that will populate job_address and job_town.

I only mentioned cust_address so I did not complicate thing too mush and confused anyone. looks as if that didn't work, sorry.

thank you for the above info as I believe I may be able to adapt it to suit my purpose (I think)

thank you Barry

User avatar
baudwalker
Veteran Member
Posts: 188
Joined: 2015-02-03 08:08
Location: Bellingen NSW Australia

Re: same address

Post by baudwalker » 2018-05-14 00:28

Thank you Pascal,

I used my method with your amendments

Code: Select all

jQuery('#job_address').val( jQuery('#address').text());
jQuery('#job_town).val( jQuery('#town).text());
and it worked perfectly. I like KISS. one file and I can see how it works at a glance.

never too old to learn

once again thank you,
Barry

Post Reply