tammyhart / Reusable-Custom-WordPress-Meta-Boxes

177 stars 97 forks source link

Javascript clone field #19

Closed Caspert closed 11 years ago

Caspert commented 11 years ago

Dear,

I have running the repeatable fields. Now I want to repeat my row, which include an image upload and a text input. I can't get it work.

I have use your code:

// Add repeatable row
jQuery('.repeatable-add').click(function() { alert('Hello there!');
    // Clone row
    field = jQuery('.ui-sortable').closest('.ui-sortable').find('.row:last').clone(true);
    fieldLocation = jQuery('.ui-sortable').closest('.ui-sortable').find('.row:last');
    jQuery('input, img', field).val('').attr('name', function(index, name) {
        return name.replace(/(\d+)/, function(fullMatch, n) {
            return Number(n) + 1;
        });
    })
    field.insertAfter(fieldLocation, jQuery(this).closest('.ui-sortable'))
    return false;
});
tammyhart commented 11 years ago

Caspert,

You should try using the most recent version of the code here instead of the code from the tutorial. There have been a lot of improvements made including to the javascript.