• Resolved arpitap

    (@arpitap)


    Hi there,

    I show in this article that you mentioned that group for non-repeatable fields are possible now, but I can’t see any documentation on how we can add that.

    I tried to add as below but when it is being saved it creates 3 copy of the same fields.

    
    $tools_metabox->add_field( [
    		'id'         => 'test',
    		'type'       => 'group',
    		'repeatable' => false, // Repeatable fields are supported w/in repeatable groups (for most types)
    		'fields'      => [
          [
    				'name' => 'test 1',
    				'id'   => 'point_0',
            'type' => 'wysiwyg',
    				'before'     => sprintf( '<span class="description">%1$s</span><span data-max-chars="80" data-count-id="_test_point_0">%2$s</span>',
    						__( 'Max. 15-30 words.', '' ),
    						MaxCharacters\get_character_count_markup( 80, '' )
    				),
    				'options'    => [
    		      'wpautop'        => true,
    		      'textarea_name'  => 'point_0',
    		      'textarea_rows'  => 3,
    		      'teeny'          => false,
    		      'default_editor' => 'tinymce',
    		      'media_buttons'  => false,
    		      'quicktags'      => true,
    		      'tinymce'        => [
    		        'resize'                => false,
    		        'wordpress_adv_hidden'  => false,
    		        'add_unload_trigger'    => false,
    		        'statusbar'             => false,
    		        'wp_autoresize_on'      => false,
    		        'verify_html'           => false, // Prevent deleting default empty tags.
    		        'toolbar1'              => 'bold,italic,link,unlink',
    		        'toolbar2'              => '',
    		      ],
    				],
    				'classes'=> [
    					'test-row',
    				],
          ],
    			[
    				'name' => 'Test 2',
    				'id'   => 'point_1',
            'type' => 'wysiwyg',
    				'before'     => sprintf( '<span class="description">%1$s</span><span data-max-chars="80" data-count-id="_test_point_1">%2$s</span>',
    						__( 'Max. 15-30 words.', '' ),
    						MaxCharacters\get_character_count_markup( 80, '' )
    				),
    				'options'    => [
    		      'wpautop'        => true,
    		      'textarea_name'  => 'point_1',
    		      'textarea_rows'  => 3,
    		      'teeny'          => false,
    		      'default_editor' => 'tinymce',
    		      'media_buttons'  => false,
    		      'quicktags'      => true,
    		      'tinymce'        => [
    		        'resize'                => false,
    		        'wordpress_adv_hidden'  => false,
    		        'add_unload_trigger'    => false,
    		        'statusbar'             => false,
    		        'wp_autoresize_on'      => false,
    		        'verify_html'           => false, // Prevent deleting default empty tags.
    		        'toolbar1'              => 'bold,italic,link,unlink',
    		        'toolbar2'              => '',
    		      ],
    				],
    				'classes'=> [
    					'test-row',
    				],
          ],
    			[
    				'name' => 'Test 3',
    				'id'   => 'point_2',
            'type' => 'wysiwyg',
    				'before'     => sprintf( '<span class="description">%1$s</span><span data-max-chars="80" data-count-id="_test_point_2">%2$s</span>',
    						__( 'Max. 15-30 words.', '' ),
    						MaxCharacters\get_character_count_markup( 80, '' )
    				),
    				'options'    => [
    		      'wpautop'        => true,
    		      'textarea_name'  => 'point_2',
    		      'textarea_rows'  => 3,
    		      'teeny'          => false,
    		      'default_editor' => 'tinymce',
    		      'media_buttons'  => false,
    		      'quicktags'      => true,
    		      'tinymce'        => [
    		        'resize'                => false,
    		        'wordpress_adv_hidden'  => false,
    		        'add_unload_trigger'    => false,
    		        'statusbar'             => false,
    		        'wp_autoresize_on'      => false,
    		        'verify_html'           => false, // Prevent deleting default empty tags.
    		        'toolbar1'              => 'bold,italic,link,unlink',
    		        'toolbar2'              => '',
    		      ],
    				],
    				'classes'=> [
    					'test-row',
    				],
          ],
        ]
    	] );
    

    Can you please advise what am I doing wrong?

    • This topic was modified 8 years, 7 months ago by arpitap.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Hi @arpitap.

    I’m not quite sure what the issue is here. I have pasted the group field provided into my local install. When the 'repeatable' => false detail is provided, the “remove group” and “add group” buttons are removed from the UI. When I remove that “repeatable” line, those two buttons return. From what I can infer with the referenced change to the plugin, it’s doing what it should be. Grouping some meta fields together, but not allowing them to be repeated in the UI. All 3 wysiwyg fields in the group are saving individual values for me.

    Just in case it’s a contributing issue, have you made sure to update to the latest version of the plugin?

    Thread Starter arpitap

    (@arpitap)

    Hi Michael,

    Thanks for the quick response.

    the fields are added as expected when I go in new Article – https://www.dropbox.com/s/1ynhgj1w2w48j2w/before-saving.jpg?dl=0

    once I publish and then come back to the article, it save as below –
    https://www.dropbox.com/s/ksisgahoqp7ccs6/after-saving.jpg?dl=0

    Thread Starter arpitap

    (@arpitap)

    it is adding 3 values in the DB, 1st one as single array of 3 objects
    other 2 are 1 array with sub-array of 3 objects

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not managing to recreate this, at least with the snippet provided. Can you provide the entirety of your CMB2 config code? Something outside of this one field may be playing a part in what you’re seeing.

    Thread Starter arpitap

    (@arpitap)

    it was doing what it was supposed to do.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    So there’s no more issue at the moment?

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘group for non-repeatable fields’ is closed to new replies.