Skip to content

Commit

Permalink
Add props for CMB2#1059, update .min, and fix issues with iterator in…
Browse files Browse the repository at this point in the history
… complex field types (e.g. address)
  • Loading branch information
jtsternberg committed Nov 27, 2017
1 parent 41582ac commit 98b74ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ All notable changes to this project will be documented in this file.

### Bug Fixes

* Fix another issue (introduced in 2.2.6) with repeatable fields not being able to save additional fields. Props [@anhskohbo](https://github.com/anhskohbo) ([#1059](https://github.com/CMB2/CMB2/pull/1059), [#1058](https://github.com/CMB2/CMB2/issues/1058)).

## [2.2.6.1 - 2017-11-24](https://github.com/CMB2/CMB2/releases/tag/v2.2.6.1)

### Enhancements
Expand Down
30 changes: 9 additions & 21 deletions js/cmb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ window.CMB2 = window.CMB2 || {};
if ( group ) {

var $other = $row.find( '[id]' ).not( cmb.repeatUpdate );
var $empty = $row.find('.empty-row').find( cmb.repeatUpdate );

// Remove extra ajaxed rows
$row.find('.cmb-repeat-table .cmb-repeat-row:not(:first-child)').remove();
Expand All @@ -422,21 +421,6 @@ window.CMB2 = window.CMB2 || {};
}
});
}

// Fix hidden empty rows
if ( $empty.length ) {
$empty.each(function() {
var $emptyField = $( this );
var oldIndex = $emptyField.attr('id').split('_').pop();
var NameRegex = new RegExp( '\\['+oldIndex+'\\]$' );
var IdRegex = new RegExp( '_'+oldIndex+'$' );
var newName = $emptyField.attr('name').replace( NameRegex, '[' + (prevNum + 1) + ']' );
var newId = $emptyField.attr('id').replace( IdRegex, '_' + ( prevNum + 1 ) );

$emptyField.attr('name', newName);
$emptyField.attr('id', newId);
});
}
}

$elements.filter( ':checked' ).removeAttr( 'checked' );
Expand Down Expand Up @@ -468,7 +452,8 @@ window.CMB2 = window.CMB2 || {};
} else {
var oldName = $newInput.attr( 'name' );
var newName;
oldID = $newInput.attr( 'id' );
oldID = $newInput.attr( 'id' );

// Handle adding groups vs rows.
if ( group ) {
// Expect another bracket after group's index closing bracket.
Expand All @@ -478,14 +463,13 @@ window.CMB2 = window.CMB2 || {};
}
else {
// Row indexes are at the very end of the string.
newName = oldName ? cmb.replaceLast( oldName, '['+ prevNum +']', '['+ cmb.idNumber +']' ) : '';
newID = oldID ? cmb.replaceLast( oldID, '_'+ prevNum, '_'+ cmb.idNumber ) : '';
newName = oldName ? cmb.replaceLast( oldName, '[' + prevNum + ']', '[' + cmb.idNumber + ']' ) : '';
newID = oldID ? cmb.replaceLast( oldID, '_' + prevNum, '_' + cmb.idNumber ) : '';
}

attrs = {
id: newID,
name: newName,
'data-iterator': cmb.idNumber,
name: newName
};

}
Expand All @@ -499,6 +483,10 @@ window.CMB2 = window.CMB2 || {};
$newInput.removeAttr( 'checked' );
}

if ( ! group && $newInput[0].hasAttribute( 'data-iterator' ) ) {
attrs['data-iterator'] = cmb.idNumber;
}

$newInput
.removeClass( 'hasDatepicker' )
.attr( attrs ).val( checkable ? checkable : '' );
Expand Down
Loading

0 comments on commit 98b74ab

Please sign in to comment.