-
Notifications
You must be signed in to change notification settings - Fork 573
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding a group row duplicates the previous row's content #257
Comments
Oooh, I'm having this problem too! I searched and searched but couldn't find anyone else reporting this, so I assumed it was something I had done. I haven't had a chances to really dig into the code to see what the problem might be. |
I believe that your problem is fixed in the latest release (2.0.5). There was an issue with subsequent repeating groups all being populated with values from the first group. |
Hmm...I don't know about the original poster, but it appears I am using version 2.0.0.7 ... so a bug introduced in 2.0.3 shouldn't affect me. But upgrading to the latest release might not be a bad idea anyway.... |
That commit was correcting some problems with the PHP. All of the PHP related functionality seems to be working. From what I can tell, the problem is that (for me at least, for some reason) calling |
@austinjreilly Please try converting your metabox registration to using the new API, demonstrated in example-functions.php and the wiki and let me know if you still see issues. |
@jtsternberg I'm still seeing the same issue. My new metabox registration code is below. Thanks for looking into this! public function notes_metabox() {
$prefix = '_journal_notes_';
$journal_notes_metabox = new_cmb2_box(array(
'id' => $prefix . 'metabox',
'title' => 'Notes',
'object_types' => array('journal'),
'context' => 'side',
'priority' => 'default',
'show_names' => false,
'sortable' => false,
//'closed' => true,
));
$journal_notes_group = $journal_notes_metabox->add_field(array(
'id' => $prefix . 'repeat_group',
'type' => 'group',
'options' => array(
'group_title' => 'Note #{#}',
'add_button' => 'Add a note',
'remove_button' => 'Remove this note',
),
));
$journal_notes_metabox->add_group_field($journal_notes_group, array(
'name' => 'Note',
'desc' => '',
'id' => 'content',
'before_row' => array($this,'get_note_author'),
'type' => 'textarea_small',
));
$journal_notes_metabox->add_group_field($journal_notes_group, array(
'name' => 'Note Author',
'desc' => '',
'id' => 'author',
'type' => 'note_author',
'default' => ''
));
} |
…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)
@austinjreilly the |
@austinjreilly it is super-odd that |
@jtsternberg Thanks for looking into this. I've upgraded to trunk. Here's what I can report:
JQMIGRATE: jQuery.fn.attr('value') no longer gets properties
console.trace()
migrateWarn @ jquery-migrate.js?ver=1.2.1:43
jQuery.attrHooks.value.get @ jquery-migrate.js?ver=1.2.1:170
m.extend.attr @ jquery.js?ver=1.11.2:4
jQuery.attr @ jquery-migrate.js?ver=1.2.1:159
m.access @ jquery.js?ver=1.11.2:3
m.fn.extend.attr @ jquery.js?ver=1.11.2:4(anonymous function) @ cmb2.js?ver=2.0.6:347
m.extend.each @ jquery.js?ver=1.11.2:2m.fn.m.each @ jquery.js?ver=1.11.2:2
window.CMB2.cmb.cleanRow @ cmb2.js?ver=2.0.6:343
window.CMB2.cmb.addGroupRow @ cmb2.js?ver=2.0.6:506
m.event.dispatch @ jquery.js?ver=1.11.2:3
m.event.add.r.handle @ jquery.js?ver=1.11.2:3 and JQMIGRATE: jQuery.fn.attr('value', val) no longer sets properties
jquery-migrate.js?ver=1.2.1:43
console.trace()
migrateWarn @ jquery-migrate.js?ver=1.2.1:43
jQuery.attrHooks.value.set @ jquery-migrate.js?ver=1.2.1:182
m.extend.attr @ jquery.js?ver=1.11.2:4jQuery.attr @ jquery-migrate.js?ver=1.2.1:159
m.access @ jquery.js?ver=1.11.2:3
m.access @ jquery.js?ver=1.11.2:3
m.fn.extend.attr @ jquery.js?ver=1.11.2:4(anonymous function) @ cmb2.js?ver=2.0.6:382
m.extend.each @ jquery.js?ver=1.11.2:2
m.fn.m.each @ jquery.js?ver=1.11.2:2
window.CMB2.cmb.cleanRow @ cmb2.js?ver=2.0.6:343
window.CMB2.cmb.addGroupRow @ cmb2.js?ver=2.0.6:506
m.event.dispatch @ jquery.js?ver=1.11.2:3
m.event.add.r.handle @ jquery.js?ver=1.11.2:3 Here is the code for my repeater field: add_filter('cmb2_init', 'research_question_metabox');
function research_question_metabox() {
$prefix = '_article_research_questions_';
$research_questions_metabox = new_cmb2_box(array(
'id' => $prefix . 'metabox',
'title' => 'Research Questions',
'object_types' => array('article'),
'context' => 'normal',
'priority' => 'default',
'show_names' => true,
'sortable' => false,
));
$research_question_group = $research_questions_metabox->add_field(array(
'id' => $prefix . 'research_question_group',
'type' => 'group',
'options' => array(
'group_title' => 'Research Question #{#}',
'add_button' => 'Add a Research Question',
'remove_button' => 'Remove this Research Question',
),
));
$research_questions_metabox->add_group_field($research_question_group, array(
'name' => 'Is this research question explicit from the manuscript?',
'desc' => '',
'id' => 'explicit',
'type' => 'radio_inline',
'options' => array('yes' => 'Yes',
'no' => 'No',
'combination' => 'Combination',
),
));
$research_questions_metabox->add_group_field($research_question_group, array(
'name' => 'Research Question',
'desc' => '',
'id' => 'research_question',
'type' => 'textarea_small',
));
} |
* Ability to use non-repeatable group fields by setting the `'repeatable'` field param to `false` when registering a group field type. Props [marcusbattle](https://github.com/marcusbattle), ([#159](CMB2/CMB2#159)). * Add and enqeueue a front-end specific CSS file which adds additional styles which are typically covered by wp-admin css. ([#311](CMB2/CMB2#311)) * Better handling of the CMB2 javascript (and CSS) required dependencies array. Dependencies are now only added conditionally based on the field types that are actually visible. ([#136](CMB2/CMB2#136)) * **THIS IS A BREAKING CHANGE:** The `group` field type's `'show_on_cb'` property now receives the `CMB2_Field` object instance as an argument instead of the `CMB2` instance. If you're using the `'show_on_cb'` property for a `group` field, please adjust accordingly. _note: you can still retrieve the `CMB2` instance via the `cmb2_get_metabox` helper function._ * New dynamic hook, `"cmb2_save_{$object_type}_fields_{$this->cmb_id}"`, to complement the existing `"cmb2_save_{$object_type}_fields"` hook. * New CMB2 property, `enqueue_js`, to disable the enqueueing of the CMB2 Javascript. * German translation provided by Friedhelm Jost. ### Bug Fixes * Fix incorrect repeatable group title number. ([#310](CMB2/CMB2#310)) * Fix obscure bug which prevented group field arguments from being passed to the sub-fields (like `show_names` and `context`). * Fixed occasional issue when adding a group row, the previous row's content would be cloned. ([#257](CMB2/CMB2#257)) git-svn-id: https://plugins.svn.wordpress.org/cmb2/trunk@1169742 b8457f37-d9ea-0310-8a92-e5e31aec5664
* Ability to use non-repeatable group fields by setting the `'repeatable'` field param to `false` when registering a group field type. Props [marcusbattle](https://github.com/marcusbattle), ([#159](CMB2/CMB2#159)). * Add and enqeueue a front-end specific CSS file which adds additional styles which are typically covered by wp-admin css. ([#311](CMB2/CMB2#311)) * Better handling of the CMB2 javascript (and CSS) required dependencies array. Dependencies are now only added conditionally based on the field types that are actually visible. ([#136](CMB2/CMB2#136)) * **THIS IS A BREAKING CHANGE:** The `group` field type's `'show_on_cb'` property now receives the `CMB2_Field` object instance as an argument instead of the `CMB2` instance. If you're using the `'show_on_cb'` property for a `group` field, please adjust accordingly. _note: you can still retrieve the `CMB2` instance via the `cmb2_get_metabox` helper function._ * New dynamic hook, `"cmb2_save_{$object_type}_fields_{$this->cmb_id}"`, to complement the existing `"cmb2_save_{$object_type}_fields"` hook. * New CMB2 property, `enqueue_js`, to disable the enqueueing of the CMB2 Javascript. * German translation provided by Friedhelm Jost. ### Bug Fixes * Fix incorrect repeatable group title number. ([#310](CMB2/CMB2#310)) * Fix obscure bug which prevented group field arguments from being passed to the sub-fields (like `show_names` and `context`). * Fixed occasional issue when adding a group row, the previous row's content would be cloned. ([#257](CMB2/CMB2#257)) git-svn-id: https://plugins.svn.wordpress.org/cmb2/trunk@1169744 b8457f37-d9ea-0310-8a92-e5e31aec5664
It's entirely possible that I'm doing something that isn't smart, so if that's the case please let me know. In any case, here's what I've got. The relevant portions of my code are below.
I am using CMB2 to create an internal "Notes" field that will add the current user id as the note author, along with the content of the note. Then on refresh, the note author will display above the note (via the
get_note_author
callback). This works with the code I have below, except that now when I click the "Add a note" button, the new note contains the old note's content and author ID.It looks to my untrained eye like something that I'm doing is preventing the
newRowHousekeeping
JavaScript function from firing, but I'm definitely not sure.Anyone have any ideas?
The text was updated successfully, but these errors were encountered: