Forums

How to set END count in Multiplier container

webkruter 01 Jul, 2015
Hello!
I have multiplier container which dublicate on button plus container with field

Param multiplier containe:

Replacer is __N___
Counter 1
Hide First YES
Disable First YES
Hide Buttons YES
Start Count 1

Code Button Plus in custom code in multiplier container:
<span class="btn btn-success btn-sm multiplier-add-button"><i class="fa fa-plus fa-lg"></i></span>

Help plz!!!
How can do than Replacer __N__ be > 10 button plus is not visible and i can't click more field?
webkruter 03 Jul, 2015
Can help me? 🤔
GreyHead 03 Jul, 2015
1 Likes
Hi webkruter,

I did this for a client using jQuery a while ago. Here is the part of the code that checks the number of lines displayed and hides the + button when it gets to max_quantity
  jQ('#garment_multiplier .multiplier-add-button').click(calculate);
  calculate();

  function calculate(){
    var quantity, base_price, material_colour, name_back, max_quantity;

    max_quantity = 5;
    // get the quantity of shirts
    name_back = jQ('#garment_multiplier :input').filter('.name_back');
    quantity = parseInt(name_back.length) - 1;
    quantity = Math.max(quantity, 1);
    jQ('#quantity').val(quantity);
    if ( quantity >= ( parseInt(max_quantity) - 1 ) ) {
      jQ('#garment_multiplier .multiplier-add-button').hide();
    } else {
      jQ('#garment_multiplier .multiplier-add-button').show();
    }
  . . .
}
This uses one of the inputs in the multiplier - 'name_back' - and counts the number of those that are inside the multiplier; then subtracts 1 because one line is hidden.

Note that this allows for the fact that some lines may be deleted and new ones added.

Bob
webkruter 03 Jul, 2015
Answer
Big Tnx GreyHead!!!! Can help how to realese whis code?

Insert into custom code in multiplier comtainer? Or JC code on load or make function?

If you have example .cf5bak it be VERY NICE!
hanxinyunus 05 May, 2016
Hi, GreyHead

Thanks for your answer, base on your information I am trying to embed the code by Load JavaScript function in Step-->On load. But from your code there is "garment_multiplier" before multiplier-add-button. May I know what is that?

Many thanks
if (typeof jQuery != 'undefined' ) {
  jQuery.noConflict();
}
jQ('#btn.btn-success.btn-sm.multiplier-add-button').click(calculate);
  calculate();

  function calculate(){
    var quantity, base_price, material_colour, name_back, max_quantity;

    max_quantity = 5;
    // get the quantity of shirts
    name_back = jQ('#btn.btn-success.btn-sm.multiplier-add-button:input').filter('.name_back');
    quantity = parseInt(name_back.length) - 1;
    quantity = Math.max(quantity, 1);
    jQ('#quantity').val(quantity);
    if ( quantity >= ( parseInt(max_quantity) - 1 ) ) {
      jQ('#btn.btn-success.btn-sm.multiplier-add-button').hide();
    } else {
      jQ('#btn.btn-success.btn-sm.multiplier-add-button').show();
    }
}
GreyHead 05 May, 2016
Hi hanxinyunus,

It's the ID of the <div> that contains the + button for the multiplier. The code catches the click event on that button, delays a little while to allow the multiplier code to run, then does the calculations including the newly added multiplier row.

Bob
This topic is locked and no more replies can be posted.