Unhide custom field after updating in view

  • Posts: 62
  • Thank you received: 0
11 years 8 months ago #93537

I have two Order custom fields.

  • Do you have a serial number? Yes/No
  • Serial Number
Serial number is set with Display limited to Do you have a serial number? = Yes.

This is all working fine but I have recently edited the custom_fields view. This now checks for and populates these fields if an existing serial number is available based on the logged in user. This is all working but for some reason the Serial Number field is still hidden unless I click on the Yes toggle, even though it is already active on yes. Also when you click yes the serial number is populated so the values are being updated bu the display is not until I click on Yes.

Any ideas on what I might be doing wrong? I would like to display the serial number field if I update the fields in the view.

Last edit: 11 years 8 months ago by Devine.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 8 months ago #93588

If there is an existing value for the coupon, you have to change the first custom field value to yes.
Are you using, radio button ? Could you give us a link to that page, and a test account ?

Please Log in or Create an account to join the conversation.

  • Posts: 62
  • Thank you received: 0
11 years 8 months ago #93816

Yeah sure, I didn't actually have this on the live site yet but I have now partially added the feature so we can test it.

www.calxa.com.au/index.php?Itemid=69&opt...=product&layout=show

Add any product to the cart then login as:
Username: hika
Password: hika

The second step in the checkout is titled Serial Number. You will note there are two front end visible fields labeled;
Do you have a serial number?
Serial Number

The 'Serial Number' fields is configured to display only when 'Do you have a serial number?' = 'Yes'

Using the hika user these fields will be populated with Yes and ThisIsASerialNumber, however the second field is not shown until you click on Yes.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 8 months ago #93875

In the view "checkout / step", at the end of the file try to add the javascript:

var serialNumber = document.getElementById('hikashop_order_order_serial_number');
if(serialNumber.value != '') serialNumber.style.display = 'inherit';

Please Log in or Create an account to join the conversation.

  • Posts: 62
  • Thank you received: 0
11 years 8 months ago #93995

I have added the script but it has not changed. I also temporarily added window.alert(serialNumber.value); which returned undefined.

Is there something wrong with the syntax for serialNumber.value to return undefined?

Please Log in or Create an account to join the conversation.

  • Posts: 62
  • Thank you received: 0
11 years 8 months ago #94045

Further to my other question regards the display of a single field, I have now also made customisations to the "checkout\fields" view. The purpose of this change is to not display the "custom_fields" at all if they are not required. Instead I am just displaying some text explaining that new serial numbers must be issued.

This is causing a problem though because I can't proceed to the next step. A message is displayed saying:

Please fill the Do you have an existing Calxa serial number? field.

I don't understand why this is when a default value of "no" should be set. If I output the value of $this->order->order_existing_serial it says "no", yet the error message suggests it is not populated.

If you would like to reproduce this to see it in action you will need to add two different but not including Monthly Subscription products to the cart. You should then get the scenario where the custom order fields are not displayed.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 8 months ago #94457

The code of xavier won't work.

The js variable serialNumber doesn't have the input field value in it.
It should actually be:

var serialNumberDiv = document.getElementById('hikashop_order_order_serial_number');
var serialNumber = document.getElementById('order_serial_number');
if(serialNumber.value != '') serialNumberDiv.style.display = 'block';

If the field is required, you can't remove its HTML. The system is done so that even if the user try to cheat by removing the HTML on the page, it won't allow the user to continue. Xavier mthod of hidding the HTML instead in CSS will allow you to reach the same function without the issue with the require check since the fields will actually still be processed.

Please Log in or Create an account to join the conversation.

  • Posts: 62
  • Thank you received: 0
11 years 8 months ago #94475

One step closer but still not quite there. It is at least recognising the serial number value now, however the style.display = 'block' does not seem to change anything. I have updated the script on the live site so you can check it out.

As a test I also removed the option to limit the display of this field. Then is I changed the 'block' to 'none' and I could see the changes reflected, so we no the script is now being correctly called. Having said this the field is still not shown when you first display the custom fields (Serial Number) step. My thoughts are that this script is being called too early and then the limit display option comes in after this one and hides it again. What script handles the conditional display of that field normally?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 8 months ago #94591

The id was the id of the input field, not the one of the radio of the first field. Try with that code instead:

var serialNumberDiv = document.getElementById('hikashop_order_order_serial_number');
var serialNumber = document.getElementById('order_existing_serial_yes');
if(serialNumber.checked) serialNumberDiv.style.display = 'block';

Please Log in or Create an account to join the conversation.

  • Posts: 62
  • Thank you received: 0
11 years 8 months ago #94643

Sorry :( Still no luck with the new script.

Do you need some more information?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 8 months ago #95109

Can you try with that code so that the JS is only run after the page is loaded:

do_nothing( function(){
var serialNumberDiv = document.getElementById('hikashop_order_order_serial_number');
var serialNumber = document.getElementById('order_existing_serial_yes');
if(serialNumber.checked) serialNumberDiv.style.display = 'block';
});

The following user(s) said Thank You: Devine

Please Log in or Create an account to join the conversation.

  • Posts: 62
  • Thank you received: 0
11 years 8 months ago #95176

Thank you much appreciated, this has now worked. :)

However as we got tied up in this problem we have left another question problem alone. I let it go because I figured it would be easier to focus on one at a time.

Anyway here is the details of my other problem. I have now also made customisations to the "checkout\fields" view. The purpose of this change is to not display the "custom_fields" at all if they are not required. Instead I am just displaying some text explaining that new serial numbers must be issued.

This is causing a problem though because I can't proceed to the next step. A message is displayed saying:

Please fill the Do you have an existing Calxa serial number? field.

I don't understand why this is when a default value of "no" should be set. If I output the value of $this->order->order_existing_serial it says "no", yet the error message suggests it is not populated.

If you would like to reproduce this to see it in action you will need to add two different but not including Monthly Subscription products to the cart. You should then get the scenario where the custom order fields are not displayed.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 8 months ago #95273

I'm guessing that the problem comes from your customization.

Please give a link to the two product pages to add to the cart to reproduce the problem and explain the modification that you did.

Please Log in or Create an account to join the conversation.

  • Posts: 62
  • Thank you received: 0
11 years 8 months ago #95385

www.calxa.com.au/index.php?option=com_hi...ayout=show&Itemid=69

On this page add the Calxa Premier 1 Year Subscription and the Calxa Premier 3 Year Subscription. Now login and proceed to the Serial Number step. If you click next on this step it returns the message saying Please fill the Do you have an existing Calxa serial number? field.

Here is the custom view checkout / fields.php

<?php
/**
 * @package	HikaShop for Joomla!
 * @version	2.0.0
 * @author	hikashop.com
 * @copyright	(C) 2010-2012 HIKARI SOFTWARE. All rights reserved.
 * @license	GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
 */
defined('_JEXEC') or die('Restricted access');
?>
<?php
$multipleProducts = false;
$cartClass = hikashop_get('class.cart');
$cart = $cartClass->loadFullCart(true);
if(count($cart->products) > 1) {
    $multipleProducts = true;
}
if(hikashop_level(2) && !empty($this->extraFields['order']) && !$multipleProducts){ ?>
<div  id="hikashop_checkout_additional_info" class="hikashop_checkout_additional_info">
	<fieldset class="input">
		<legend><?php echo JText::_('ADDITIONAL_INFORMATION');?></legend>
		<table cellpadding="0" cellspacing="0" border="0" class="hikashop_contentpane">
	<?php
		if(!empty($this->extraFields['order'])){
			JRequest::setVar('hikashop_check_order',1);
			$this->setLayout('custom_fields');
			$this->type = 'order';
			echo $this->loadTemplate();
		}
	?>
		</table>
	</fieldset>
</div>
<div style="clear:both"></div>
<?php } else {?>
<div  id="hikashop_checkout_additional_info" class="hikashop_checkout_additional_info">
    <p>You may not use an existing serial number to purchase multiple products. <br /><strong>Press Next to continue and issue new serial numbers.</strong></p>
    <p>Otherwise remove a product from the cart and you may renew your Calxa product with an existing serial number.</p>
<?php } ?>

Last edit: 11 years 8 months ago by Devine.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 8 months ago #95658

Hi,

Your code is not correct.
You should add hidden input fields to replace the custom fields that you don't display in your else block of code.

<input type="hidden" name="data[order][order_existing_serial]" value="no" id="order_existing_serial_no" checked="checked" />
<input class="hidden" id="order_serial_number" size="50" maxlength="50" type="text" name="data[order][order_serial_number]" value="ThisIsASerialNumber" />

The following user(s) said Thank You: Devine

Please Log in or Create an account to join the conversation.

  • Posts: 62
  • Thank you received: 0
11 years 3 months ago #116339

Hello,

As described in previous posts I have my fields step as a separate step in the checkout (login_address_shipping_coupon,fields,payment_terms_confirm_cart_status,end). My problem is that you need to click Next twice to proceed to the next step. I assume this has always been an issue since I made the above customisations but I have only just noticed it. Perhaps it is only an issue because the Fields step is on it's own but I do require this to be a separate step.

If you do click past this step to the payment step and then go back you no longer require to click next twice, so I assume the fields are not being marked as OK early enough to proceed the first time.

Can you please assist me with this as I would like the user to be able to fill out the fields and then proceed without having to click next twice?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 3 months ago #116484

Hi,

I have no idea. I remember such bug in previous versions of HikaShop but we don't have the problem with the latest version on our end and I don't see why the modifications of this thread would change that.
Did you try on a copy of your website with the latest version of HikaShop ? If it still doesn't work, does it work if you remove your changes ?

Please Log in or Create an account to join the conversation.

Time to create page: 0.102 seconds
Powered by Kunena Forum