Skip to content

Commit

Permalink
Fix issues related to group repeatable subsequent rows when there is …
Browse files Browse the repository at this point in the history
…a checkbox or radio input.

If the input is a checkbox or radio, the original value is needed or saving will not save the value (subsequent post saves work because inputs  will then have the required value set).
This patch conditionally adds values to radios and inputs on new repeatable and sets the checked attribute only on the default option (radios).
Fixes issue CMB2#257 (this will set reset text inputs as well), and CMB2#246 & CMB2#263(restores radio and checkbox values on new row saves)
  • Loading branch information
Miles Fink committed Apr 28, 2015
1 parent d0c5c68 commit d06cc9d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions js/cmb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ window.CMB2 = (function(window, document, $, undefined){
var $newInput = $(this);
var isEditor = $newInput.hasClass( 'wp-editor-area' );
var oldFor = $newInput.attr( 'for' );
var oldVal = $newInput.val();
// var $next = $newInput.next();
var attrs = {};
var newID, oldID;
Expand All @@ -358,14 +359,22 @@ window.CMB2 = (function(window, document, $, undefined){
attrs = {
id: newID,
name: newName,
// value: '',
value: '',
'data-iterator': cmb.idNumber,
};
if ( ($newInput.is(':checkbox') || $newInput.is(':radio') ) ) {
if (oldVal == "") {
attrs.checked = "checked";
} else {
attrs.value = oldVal;
$newInput.removeAttr("checked");
}
}
}

$newInput
.removeClass( 'hasDatepicker' )
.attr( attrs ).val('');
.attr( attrs );

// wysiwyg field
if ( isEditor ) {
Expand Down

0 comments on commit d06cc9d

Please sign in to comment.