Checkout form submit

  • Posts: 1119
  • Thank you received: 114
6 years 1 month ago #299427

-- HikaShop version -- : 1810220946

Hi,

We have intergrated jquery validation plugin to validate form fields. All works fine everwhere except checkout guest/address block.

The issue is that on focusing any input and pressing keyboard "enter" or mobile browser "go", the address block is submited those bypassing validation plugin. I also have tried in HikaShop » User addresses menu item which has now ajax submit and there is no such issue.

So before applying any changes to validation plugin it self, is there a way to avoid such behiviour on hikashop level?
Basically i am looking for the part of the code which gives such undesired effect.

For sure tried with protostar template without any modifications and it has same behiviour on checkout as well.

Any help would be appreciated.

Thank you

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
6 years 1 month ago #299433

Hi,

There is no way to avoid that. It's done on purpose thanks to the handleEnter function in the file media/com_hikashop/js/checkout.js so that when you use the enter key it submits the block.
However, your issue brings a good point.
I've just added on our end a trigger checkoutBlockSubmit that you can register to add checks before the block data is sent in AJAX.
You can first download again the install package on our website and install it on yours to get the patch to the checkout javascript to handle that new trigger event.
Then, you can do like that in your JS:

window.Oby.registerAjax(['checkoutBlockSubmit'], function(type, cid, pos, element){
	// my checks on the form
   if(error_in_the_form){
  alert('there is an error');
    return true;
  }
});

Last edit: 6 years 1 month ago by nicolas.
The following user(s) said Thank You: kyratn

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

  • Posts: 1119
  • Thank you received: 114
6 years 1 month ago #299455

Hi.

I saw that my issue probably comes from checkout.js file. That's why i created this topic.

Thank you for the new trigger. This now makes things simpler :)


Kind regarss

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

  • Posts: 1119
  • Thank you received: 114
5 years 3 weeks ago #312567

Hi,

I am trying to change some behavior in checkout with jQuery validation plugin...

The issue is that when i try to validate address block, i am not able to change guest information ( trying to press button 'change" will return erros in address block ), until address is validated. It seems that "checkoutBlockSubmit" is registering all checkout blocks... Is there a way to check which block you are submiting? So i could have different rules for it?

The code looks like this:

  $("#hikashop_checkout_form").validate({
   rules: {
	 "data[register][email]": {
        required: {
        depends:function(){
            $(this).val($.trim($(this).val()));
            return true;
          }
        },
        lowAllLetters: true,
        email: true
      },
      "data[address_1_4][address_firstname]": {
       required: true,
        capFirstStringLetter: true,
        minlength: 3
      }
   },
   messages: {
	 "data[register][email]": "error email",
     "data[address_1_4][address_firstname]": "error name",
   },
   errorElement: "div",
   errorPlacement: function ( error, element ) {
		error.addClass( "invalid-feedback" );
	    error.insertAfter( element );
	},
	highlight: function ( element, errorClass, validClass ) {
		$(element).addClass( "is-invalid" );
	},
	unhighlight: function (element, errorClass, validClass) {
		$(element).removeClass( "is-invalid" );
    }
 });
	  
window.Oby.registerAjax(['checkoutBlockSubmit'], function(type, cid, pos, element){
      if (!$("#hikashop_checkout_form").valid()) {
        return true;
      }
  });

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 3 weeks ago #312585

Hi,

Yes, the trigger checkoutBlockSubmit is used for each and every view where you can submit some information.
So you need to use the variables type cid and pos to check whether you want to do your checks.

The following user(s) said Thank You: kyratn

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

  • Posts: 1119
  • Thank you received: 114
5 years 3 weeks ago #312630

Hi,

Thanks Nicolas, i have manage to do what i need. However i found some kinda issue with the trigger while doing my customization.

The issue.

While in edit address mode, clearing any address input and pressing ok button will trigger error on that input and it is fine, but after this, i am not able to finish the checkout or go to next step. It's just nothing happens... The "hikabtn_checkout_next" seems doesn't work anymore until i refresh page...

There is no such issue if error is triggered with "Enter" key, it only effects the "ok" button of address block and only after pressing it and triggering the error...

Fixed it with removing the line "onsubmit="if(window.checkout.onFormSubmit){ return window.checkout.onFormSubmit(this); }" inside checkout show.php

So question: Is this me or it could be that the issue is with the trigger?

I lack of knowledge to understand so thought will let you know.

Kind Regards

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
5 years 3 weeks ago #312647

Hi,

There is no issue with the trigger.
You need to look at the code of the function setLoading in media/com_hikashop/js/checkout.js
You'll see this:

setLoading: function(el, load) {
		var w = window, o = w.Oby, t = this, d = document, btn = d.getElementById('hikabtn_checkout_next');
		if(el) {
			if(load)
				o.addClass(el, "hikashop_checkout_loading");
			else
				o.removeClass(el, "hikashop_checkout_loading");
		}
		if(load)
			t.loading++;
		else if(t.loading > 0)
			t.loading--;
		// we block the next button while blocks are being submitted to avoid wrong actions to be validated while finishing the checkout
		if(btn) {
			if(t.loading) {
				btn.disabled = true;
				o.addClass(btn, 'next_button_disabled');
			} else  {
				btn.disabled = false;
				o.removeClass(btn, 'next_button_disabled');
			}
		}
	}
As you can see, there is a mechanism to prevent the users from using the next button while blocks are being submitted.
So if the btn.disabled variable is not set back to true, the next button won't work.
In the submitBlock function, there is a call to t.setLoading(el, false); to reset the next button state after an AJAX call so that the next button can be used again after the block is submit.
But I suppose that the code you have somehow skips resetting the state of the next button.

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

Time to create page: 0.121 seconds
Powered by Kunena Forum