News:

Looking for documentation? Take a look on our wiki

Main Menu

Only radios and selects supported as custom fields

Started by balai, October 22, 2019, 15:10:06 PM

Previous topic - Next topic

balai

I noticed that the price recalculate function is triggered only if the custom fields are radio buttons or select lists.

Examining the file: components/com_virtuemart/assets/js/vmprices.js
and the function: Virtuemart.product, it turns out that this is true.

That means that out of 22 html input types only 1 is supported (i.e. radio).

My suggestion is the recalculate function (i.e. Virtuemart.eventsetproducttype) to support any input.
I think it could be a good step towards the extensibility of the custom fields.

Suggested modification.
file: components/com_virtuemart/assets/js/vmprices.js
Virtuemart.product = function(carts) {
carts.each(function(){
var cart = jQuery(this),

quantityInput=cart.find('input[name="quantity[]"]'),
plus   = cart.find('.quantity-plus'),
minus  = cart.find('.quantity-minus'),
select = cart.find('select:not(.no-vm-bind)'),
input = cart.find('input:not(.no-vm-bind)'),
virtuemart_product_id = cart.find('input[name="virtuemart_product_id[]"]').val(),
quantity = cart.find('.quantity-input');
var Ste = parseInt(quantityInput.attr("step"));
//Fallback for layouts lower than 2.0.18b
if(isNaN(Ste)) { Ste = 1; }
        this.action ="#";

        plus
            .off('click', Virtuemart.incrQuantity)
            .on('click', {cart:cart}, Virtuemart.incrQuantity);

        minus
            .off('click', Virtuemart.decrQuantity)
            .on('click', {cart:cart},Virtuemart.decrQuantity);

        select
            .off('change', Virtuemart.eventsetproducttype)
            .on('change', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);

        input
            .off('change', Virtuemart.eventsetproducttype)
            .on('change', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);

        quantity
            .off('click blur submit', Virtuemart.quantityErrorAlert)
            .on('click blur submit', Virtuemart.quantityErrorAlert)
.off('keyup', Virtuemart.eventsetproducttype)
.on('keyup', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);


        var addtocart = cart.find('button[name="addtocart"], input[name="addtocart"], a[name="addtocart"]');

        addtocart
            .off('click submit',Virtuemart.addtocart)
            .on('click submit',{cart:cart},Virtuemart.addtocart);

});
}

Studio 42

input = cart.find('input:not(.no-vm-bind)') mean any inputs excluded this having class "no-vm-bind"
So all are accepted !

balai

Studio24 This is the code i submitted.
Kind request: Please examine an issue, before posting.

Studio 42

You are right, but VM core do not use other inputs.
I implement in my plugin the trigger similar to this
        $('.myplugininput')
            .off('change', Virtuemart.eventsetproducttype)
            .on('change', {cart:cart,virtuemart_product_id:virtuemart_product_id},Virtuemart.eventsetproducttype);

You can extract the product id and the cart yourself

balai

Thank you but i am suggesting that as a core feature. This is why i opened it in that category.

Waiting some feedback from the core developers.