Multi-field Drop-down and session variables persistence

Any tips and tricks that has to with the ADDT that doesn't fit into one of the other categories
piripacchio
Posts: 37
Joined: 2010-04-28 08:34

Multi-field Drop-down and session variables persistence

Post by piripacchio » 2016-03-22 18:09

Hi all,
I developed a page that uses the Multi-Field Drop-down (MFDD).
It works "almost" perfectly.

The page, basically, allows me to enter 10 fields (text input) or to select a preset from a dropdown menu (MFDD) that will fill all 10 fields automatically.
The form will save all 10 fields in session variables too.
The default value for every field is set to the a session variable.
But even if the session variables are set, the MFDD will reset all fields, when the page will be reloaded.
I think this is due to the MFDD behaviour that will populate the 10 fielsd automatically.

Is there a way to force the MFDD to use the sesson variables if they are set and you didn't selected a preset from the dropdown menu?
The MFDD code seems too much unclear to me.
Is there someone that had the same problem?

TIA for any suggestion.

Tony

User avatar
Fred
Site Admin
Posts: 491
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: Multi-field Drop-down and session variables persistence

Post by Fred » 2016-03-23 01:08

Tony is that the ADDT version of the Interakt "Dependant Dropdown" server behaviour?

piripacchio
Posts: 37
Joined: 2010-04-28 08:34

Re: Multi-field Drop-down and session variables persistence

Post by piripacchio » 2016-03-23 09:25

No, Fred,
it's not the "dependent drop down" server behaviour, it's the Multi-Field Drop-Down.
Ciao ;).

tony

User avatar
Fred
Site Admin
Posts: 491
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: Multi-field Drop-down and session variables persistence

Post by Fred » 2016-03-23 11:18

Believe it or not I have never used it. Had to go and look if I have it installed... :P
Probably been put of it by the way the dependant dropdown works. (it loads all the possible options of the first dropdown into the script soit becomes extremely slow if you have a long list of option)

I use a JSON call to achieve the same as what you want.
What I have done is to use jquery to display a different set of input fields that is populated from the session variables and if a selection is made then hide those and display and populate the proper fields.

Probably not the most elegant way but it works.... so far anyway...

piripacchio
Posts: 37
Joined: 2010-04-28 08:34

Re: Multi-field Drop-down and session variables persistence

Post by piripacchio » 2016-03-23 11:23

Thanks, Fred,
I'll try a custom solution too.

ciao ;).

tony

User avatar
Fred
Site Admin
Posts: 491
Joined: 2010-02-15 12:10
Location: Armagh, Northern Ireland
Contact:

Re: Multi-field Drop-down and session variables persistence

Post by Fred » 2016-03-23 13:41

Tony here is my script I am using.

What I have is in my e-commerce module the client can either enter their delivery address or select from a list of "collection points"/
In both cases the "same" fields needs to be completed.
Selecting the "collection points" is via a dynamic list of radio buttons that is "hidded" and replaced with a list of names.

Hope this helps you in the right direction.

Code: Select all

 $(document).ready(function(){
 	//alert("Jquery Loaded OK"); // Debug
	// Hide the jquery/JSON fields and set them as disabled to use the normal html dropdowns
		$("#alt_collections").hide();
		$('#ship_method_test').hide();
		$('#ship_method_test').prop('disabled', true);
		$('#shipstate_ord_test').hide();
		$('#shipstate_ord_test').prop('disabled', true);
		var col_id = 0;
		var col_load = 0;
		//window.col_load = 0;
		
		// If a collection point radio has been clicked
  			$("#checkbox_div input:radio").click(function() {
			var col_id = $(this).val(); //Get the record ID from the radio value
				if (col_id > 9999999) {
						if (col_load > 0) {
											alert("We need to refresh the page\n\rPlease select the same option again after the page reloaded.");
											location.reload(true);
											return;
										}
    			//alert("Radio Clicked");  // Debug
						$.getJSON('../custom/shopCollect.php?col_id=' + col_id, // Build the JSON query string
        				function(data){
					// Set the form fields to the JSON retrieved values
					//alert('Collection Point Selected.');  // Debug
							$("#shipname_ord").val(data.Name);
            				$("#shipstreetaddress_ord").val(data.Address);
            				$("#shipcity_ord").val(data.City);
            				$("#shipzip_ord").val(data.Postal);
							$("#shipzip_ord").val(data.Postal);
							$("#shipcountry_ord").val(data.Country);
							$('#shipstate_ord').remove();
							$('#shipstate_ord_test').show();
							$('#shipstate_ord_test').prop('disabled', false);
							$("#shipstate_ord_test").val(data.County);
							$("#shipmethod_ord").load("shipDropdown.php?choice=" + $("#shipcountry_ord").val()+"&tot_w=<?php echo $row_Recordset1['MXK_Total_weight'];?>");
							// Scroll to confirm button after field completion.
							$('html, body').animate({
							scrollTop: $("#scroll_to").offset().top
							}, 2000);
							});

				} else {
							col_load = 1;
						// Hide collection options after click
							$("#alt_collections").hide( "slow", function() {
							});

						// Remove the html fields
							$('#shipstate_ord').remove();
							$('#shipmethod_ord').remove();
						// Show the jquery/JSON fields
							$('#ship_method_test').show();
							$('#shipstate_ord_test').show();
						// Enable the jquery/JSON fields
							$('#ship_method_test').prop('disabled', false);
							$('#shipstate_ord_test').prop('disabled', false);
    					//alert("Radio Clicked");  // Debug
								$.getJSON('../custom/shopCollect.php?col_id=' + col_id, // Build the JSON query string
        						function(data){
							// Set the form fields to the JSON retrieved values
							//alert('Collection Point Selected.');  // Debug
            						$("#shipname_ord").val(data.Name);
            						$("#shipstreetaddress_ord").val(data.Address);
            						$("#shipcity_ord").val(data.City);
            						$("#shipzip_ord").val(data.Postal);
									$("#shipcountry_ord").val(data.Country);
									$("#shipstate_ord_test").val(data.County);
									$("#ship_method_test").val(data.Ship);
							// Scroll to confirm button after field completion.
							$('html, body').animate({
							scrollTop: $("#scroll_to").offset().top
							}, 2000);									
									});
						}// Close "else"
			});
							
});

Post Reply