Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm one of the contributors for the Meta Box Class here on Github (link) and before I get too deep, I wanted to ask if anyone knew of a straight forward way to allow users to add additional fields "on the fly", having an "add" button with a text field to add additional fields (i.e. list items). I've seen this done a few ways in the past, but I'm all for not reinventing the wheel.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Agreed, I've seen it too, but I don't think there's any readily available API or method.

For me, I use a lick of jQuery;

<input type="text" class="list-item" name="list_items[]" />
<input type="button" class="button-secondary" id="add-list" />

<script type="text/javascript">
    ( function( $ ) {
        $( '#add-list' ).click( function() {
            var $item =  $( '.list-item:last' ), $new = $item.clone();
            $item.after( $new.val( '' ) );
        }
    })( jQuery );
</script>

Note that you might wanna tweak those selectors if you plan on having multiple 'instances' of these.

share|improve this answer
add comment

take a look at the WP alchemy metabox class. Dimas has already sorted that out w/ his have_fields_and_multi setup

farinspace.com/wpalchemy-metabox/

share|improve this answer
    
yeah, I know they have it, but they've built their entire structure differently than I have. Not looking to swap out, rather, get it in the class I've developed. –  Norcross Jun 30 '11 at 3:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.