Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions js/fieldmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ var init_sortable_container = function( el ) {
$( document ).trigger( 'fm_sortable_drag', el );
},
stop: function( e, ui ) {
var $parent = ui.item.parents( '.fm-wrapper' ).first();
fm_renumber( $parent );
fm_renumber( ui.item.closest( '.fm-wrapper[data-fm-array-position]' ) );
$( document ).trigger( 'fm_sortable_drop', el );
}
} );
Expand Down Expand Up @@ -96,7 +95,6 @@ var init_label_macros = function() {
return; // continue;
}

// TODO: nested fields get iterated over multiple times, is this avoidable?
$( this ).find( '.fm-element, .fm-incrementable' ).each( function() {
var $element = $( this );
var fname = $element.attr( 'name' );
Expand Down Expand Up @@ -142,7 +140,7 @@ var init_label_macros = function() {
}

// Iterate over subgroups.
fm_renumber( $( this ).find( '.fm-wrapper' ) );
fm_renumber( $( this ).find( '.fm-wrapper[data-fm-array-position]' ) );

// Remove temporary name prefix in renumbered fields.
if ( modified_elements.length ) {
Expand Down Expand Up @@ -194,9 +192,12 @@ fm_add_another = function( $element ) {
var $new_element = $( '.fmjs-proto.fm-' + el_name, $element.closest( '.fm-wrapper' ) ).first().clone();

$new_element.removeClass( 'fmjs-proto' );
$new_element = add_more_position == "bottom" ? $new_element.insertBefore( $element.parent() ) :
$new_element.insertAfter( $element.parent() ) ;
fm_renumber( $element.parents( '.fm-wrapper' ) );
$new_element = add_more_position == "bottom"
? $new_element.insertBefore( $element.parent() )
: $new_element.insertAfter( $element.parent() );

fm_renumber( $element.closest( '.fm-wrapper[data-fm-array-position]' ) );

// Trigger for subclasses to do any post-add event handling for the new element
$element.parent().siblings().last().trigger( 'fm_added_element' );
init_label_macros();
Expand Down
4 changes: 2 additions & 2 deletions php/class-fieldmanager-field.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ public function element_markup( $values = array() ) {
$parent = $parent->parent; // parent's parent; root element has null parent which breaks while loop.
}
}
$fm_wrapper_attrs['data-fm-array-position'] = $html_array_position;
}

// Checks to see if element has display_if data values, and inserts the data attributes if it does.
Expand All @@ -558,9 +559,8 @@ public function element_markup( $values = array() ) {
$fm_wrapper_attr_string .= sprintf( '%s="%s" ', sanitize_key( $attr ), esc_attr( $val ) );
}
$out .= sprintf(
'<div class="%s" data-fm-array-position="%d" %s>',
'<div class="%s" %s>',
esc_attr( implode( ' ', $classes ) ),
absint( $html_array_position ),
$fm_wrapper_attr_string
);

Expand Down