Skip to content

Commit

Permalink
Make remove row button properly disabled when applicable
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Aug 18, 2014
1 parent 9a3790a commit c2f8b7b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions js/cmb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,11 @@ window.CMB2 = (function(window, document, $, undefined){

cmb.afterRowInsert( $newRow, true );

var disabled = ( $table.find('.repeatable-grouping').length <= 1 );
$table.find('.remove-group-row').prop( 'disabled', disabled );
if ( $table.find('.repeatable-grouping').length <= 1 ) {
$table.find('.remove-group-row').attr( 'disabled', 'disabled' );
} else {
$table.find('.remove-group-row').removeAttr( 'disabled' );
}

$table.trigger( 'cmb2_add_row', $newRow );
};
Expand All @@ -484,7 +487,7 @@ window.CMB2 = (function(window, document, $, undefined){
cmb.afterRowInsert( $row );
$table.trigger( 'cmb2_add_row', $row );

$table.find( '.remove-row-button' ).prop( 'disabled', false );
$table.find( '.remove-row-button' ).removeAttr( 'disabled' );

};

Expand All @@ -498,12 +501,14 @@ window.CMB2 = (function(window, document, $, undefined){
if ( number > 1 ) {
// when a group is removed loop through all next groups and update fields names
$parent.nextAll( '.repeatable-grouping' ).find( cmb.repeatEls ).each( cmb.updateNameAttr );
cmb.log( 'number', number );

$parent.remove();
$table
.trigger( 'cmb2_remove_row' )
.find('.remove-group-row').prop( 'disabled', number <= 2 );
if ( number <= 2 ) {
$table.find('.remove-group-row').attr( 'disabled', 'disabled' );
} else {
$table.find('.remove-group-row').removeAttr( 'disabled' );
}
$table.trigger( 'cmb2_remove_row' );
}

};
Expand All @@ -521,11 +526,11 @@ window.CMB2 = (function(window, document, $, undefined){
}
$self.parents('.cmb-repeat-table .cmb-row').remove();
if ( number === 3 ) {
$table.find( '.remove-row-button' ).prop( 'disabled', true );
$table.find( '.remove-row-button' ).attr( 'disabled', 'disabled' );
}
$table.trigger( 'cmb2_remove_row' );
} else {
$self.prop( 'disabled', true );
$self.attr( 'disabled', 'disabled' );
}
};

Expand Down
Loading

0 comments on commit c2f8b7b

Please sign in to comment.