Forum

Thread tagged as: Question, Shop

Clone cart property

Hi All

im using cart property to submit details during checkout

and i have the form like this

<perch:form id="participants" app="perch_shop" >
            <div id="entry1" class="clonedInput">
                <h2 id="form2_title" name="form2_title" class="heading-reference">Entry #1</h2>
                <fieldset>
                    <div class="large-12 columns">
                        <perch:input class="input_ac" type="text"  id="activity" cart-property="activity" placeholder="Activity"/>
                    </div>
                    <div class="large-12 columns">
                        <perch:input class="input_d1" type="date"  id="firstDate" cart-property="firstDate" />
                    </div>
                    <div class="large-12 columns">
                        <perch:input class="input_d2" type="date"  id="secondDate" cart-property="seccondDate" />
                    </div>
                </fieldset>


            </div><!-- end #entry1 -->

            <div id="addDelButtons">
                <input type="button" id="btnAdd" value="add section"> <input type="button" id="btnDel" value="remove section above">
            </div>


            <fieldset class="check">
                <label><input type="checkbox"> I accept the terms of service.</label>
            </fieldset>

            <fieldset class="form-actions">
                <perch:input id="checkout" type="submit" value="&#xf07a; Checkout now" class="add-to-cart button"/>
            </fieldset>
       </perch:form>     

i have some jQuery that clones the form fields

is there a way to incriment the cart property ID ~~~ cart-property="firstDate" ~~

Anthony Elleray

Anthony Elleray 2 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Would the logical place to do that not be in your jQuery code?

I've tried but in the outputted html there's nothing to target like the id= or name=

this is my jQuery

$(function () {
    $('#btnAdd').click(function () {
        var num     = $('.clonedInput').length, // Checks to see how many "duplicatable" input fields we currently have
            newNum  = new Number(num + 1),      // The numeric ID of the new input field being added, increasing by 1 each time
            newElem = $('#entry' + num).clone().attr('id', 'entry' + newNum).fadeIn('slow'); // create the new element via clone(), and manipulate it's ID using newNum value


newElem.find('.input_ac').attr('id', 'form2_activity' + newNum).attr('name', 'activity' + newNum).val('').attr('cart-property', 'activity' + newNum).val('');


});

Drew McLellan

Drew McLellan 2638 points
Perch Support

You could add data- attributes if needed.

not sure i follow sorry

so like

 newElem.find('.input_ac').attr('id', 'form2_activity' + newNum).attr('name', 'activity' + newNum).val('').data('cart-property', 'activity' + newNum).val('');
Drew McLellan

Drew McLellan 2638 points
Perch Support

No, I meant like:

<perch:input class="input_ac" type="text"  id="activity" cart-property="activity" placeholder="Activity" data-name="activity" />

or what have you. Either way, I'm not sure this is a Perch support issue.