Arrange custom fields with drag and drop?

In this example of repeatable custom fields, we can see that the following jQuery is needed:

$('#repeatable-fieldset-one tbody').sortable({
    opacity: 0.6,
    revert: true,
    cursor: 'move',
    handle: '.sort'
});

And the HTML it controls is (simplified):

<table id="repeatable-fieldset-one" width="100%">
<thead>
    <tr>
        <th width="2%"></th>
        <th width="30%">Name</th>
        <th width="60%">URL</th>
        <th width="2%"></th>
    </tr>
</thead>
<tbody>
<?php
if ( $repeatable_fields ) :
    foreach ( $repeatable_fields as $field ) {
    ?>
        <tr>
            <td><a class="button remove-row" href="#">-</a></td>
            <td>NAME FIELD</td>
            <td>URL FIELD</td>
            <td><a class="sort">|||</a></td>
        </tr>
    <?php
    }
endif;

Leave a Comment