Forum Replies Created

Viewing 15 replies - 151 through 165 (of 184 total)
  • Thread Starter dkurth

    (@dkurth)

    Michael..I am totally lost with JS. Since I did not write this tool kit, I have no clue (uncomfortable feeling) of where to even begin. Thanks for the snippet, I have not idea what to do with it. Thoughts?

    Thread Starter dkurth

    (@dkurth)

    YOu can “harp” all you want. I am willing to try any a good argument. I have just never seen a “variable” override function before in any SDK. So it did not make sense to me. But ok, if you are saying that the override value is flexible, I can try it.

    Thread Starter dkurth

    (@dkurth)

    i am not not a javascript queen. I really hate the language and i get frustrate with it. Any trouble i ever have with websites is always because of javascript. That said, i know this is based on it. Can you make some suggestions on how to do that?

    The reason i do not understand why a naming convention would make any difference is that it is just a call back assignment to a function call, this which is “fixed” address no matter what it’s name. Not a variable. I did put it in, but it made no difference.

    Thread Starter dkurth

    (@dkurth)

    Adding some supporting information:

    The site starting acting werid, so I removed the code above and things are back to normal. I have additional questions pf whether using the postid, like I did, causes issues. It was from the online example, but I am open to suggestions.

    Would it better that I create another custom post? These fields are for a user profile information containing their subscription data and the ability to change information. There is no “new post”, just updating my local table. But the could also have more than one set of subscription data, thus the repeatable fields.

    What they can not do, is add records or delete records. That is through woocommerce in the subscription section.

    Ultimately, I am looking for another windows into particular user’s subscription information, that I have stored in my own table.

    Thread Starter dkurth

    (@dkurth)

    ja i just found those. I was thinking the sort would be above all the posts and would have alphabetically orients all the repeatable fields.. like in the standard post directory .

    Since i keep my forms closed with the business name visible, would have been nice to have a similar button that would have ordered them, instead of by order of entry or one by one move up a list.

    Since my fields entry forms can have hundreds of records , it would have made it easier to work with.

    You don’t know of any add on in which i could put something like this up for the field groups do you ?

    • This reply was modified 6 years ago by dkurth.
    Thread Starter dkurth

    (@dkurth)

    Awesome job

    Thread Starter dkurth

    (@dkurth)

    BINGO! Thank you.

    (See how language is different from one person to the next. When you showed in the sample “yourprefix_group_titles_metabox” I took that to be the group title id.

    Thread Starter dkurth

    (@dkurth)

    So the id of the field you want to use. Got it.
    Yet when I replace:

    var $box = $( document.getElementById( 'title' ) );'
    
    (the name of the field), nothing happens
    
    

    Here is a sample of one of the group fields. The one I want to use.

    $cmb->add_group_field( $group_field_id, array(
    	                             'name'            => 'test',
    	                             'id'              => 'title',
    	                             'type'            => 'title',
    							  'sanitization_cb' => false,
    							  'escape_cb'       => false,
    							  'on_front'        => false,
    								 									 
                                ) );  
    
    Thread Starter dkurth

    (@dkurth)

    Found this a few minutes ago…and posted in that question.
    https://github.com/CMB2/CMB2-Snippet-Library/blob/master/javascript/dynamically-change-group-field-title-from-subfield.php

    I tried it, but it is not working. Do yo see anything incorrect?

    $group_field_id = $cmb->add_field( array(
    	'id'          => 'MMDListsRecord',
    	'type'        => 'group',
    	'description' => __( 'Individual Directory Listings', 'mmd' ),
    	'options'     => array(
    		'group_title'       => __( 'Record {#}', 'mmd' ), // since version 1.1.4, {#} gets replaced by row number
    		'add_button'        => __( 'Add Another Record', 'mmd' ),
    		'remove_button'     => __( 'Remove Record', 'mmd' ),
    		'sortable'          => true,
    		'closed'            => true,
    	),
      'after_group' => 'mmdlist_add_js_for_repeatable_titles',
    ) );
    
    function mmdlist_add_js_for_repeatable_titles() {
    	add_action( is_admin() ? 'admin_footer' : 'wp_footer', 'mmdlist_add_js_for_repeatable_titles_to_footer' );
    }
    
    function mmdlist_add_js_for_repeatable_titles_to_footer() {
    	?>
    	<script type="text/javascript">
    	jQuery( function( $ ) {
    		var $box = $( document.getElementById( 'MMDListsRecord' ) );
    		var replaceTitles = function() {
    			$box.find( '.cmb-group-title' ).each( function() {
    				var $this = $( this );
    				var txt = $this.next().find( '[id$="title"]' ).val();
    				var rowindex;
    				if ( ! txt ) {
    					txt = $box.find( '[data-grouptitle]' ).data( 'grouptitle' );
    					if ( txt ) {
    						rowindex = $this.parents( '[data-iterator]' ).data( 'iterator' );
    						txt = txt.replace( '{#}', ( rowindex + 1 ) );
    					}
    				}
    				if ( txt ) {
    					$this.text( txt );
    				}
    			});
    		};
    		var replaceOnKeyUp = function( evt ) {
    			var $this = $( evt.target );
    			var id = 'title';
    			if ( evt.target.id.indexOf(id, evt.target.id.length - id.length) !== -1 ) {
    				$this.parents( '.cmb-row.cmb-repeatable-grouping' ).find( '.cmb-group-title' ).text( $this.val() );
    			}
    		};
    		$box
    			.on( 'cmb2_add_row cmb2_remove_row cmb2_shift_rows_complete', replaceTitles )
    			.on( 'keyup', replaceOnKeyUp );
    		replaceTitles();
    	});
    	</script>
    	<?php
    }
    

    I even tried adding the prefix to the call. Nothing. I must be missing something.

    • This reply was modified 6 years ago by dkurth.
    • This reply was modified 6 years ago by dkurth.
    dkurth

    (@dkurth)

    Trying to do this as well. I must be missing something, since when I added the suggested code snippet, nothing happens.

    $group_field_id = $cmb->add_field( array(
    	'id'          => 'MMDListsRecord',
    	'type'        => 'group',
    	'description' => __( 'Individual Directory Listings', 'mmd' ),
    	'options'     => array(
    		'group_title'       => __( 'Record {#}', 'mmd' ), // since version 1.1.4, {#} gets replaced by row number
    		'add_button'        => __( 'Add Another Record', 'mmd' ),
    		'remove_button'     => __( 'Remove Record', 'mmd' ),
    		'sortable'          => true,
    		'closed'            => true,
    	),
      'after_group' => 'add_js_for_repeatable_titles',
    ) );
    
    function add_js_for_repeatable_titles() {
    	add_action( is_admin() ? 'admin_footer' : 'wp_footer', 'add_js_for_repeatable_titles_to_footer' );
    }
    
    function add_js_for_repeatable_titles_to_footer() {
    	?>
    	<script type="text/javascript">
    	jQuery( function( $ ) {
    		var $box = $( document.getElementById( 'MMDListsRecord' ) );
    		var replaceTitles = function() {
    			$box.find( '.cmb-group-title' ).each( function() {
    				var $this = $( this );
    				var txt = $this.next().find( '[id$="title"]' ).val();
    				var rowindex;
    				if ( ! txt ) {
    					txt = $box.find( '[data-grouptitle]' ).data( 'grouptitle' );
    					if ( txt ) {
    						rowindex = $this.parents( '[data-iterator]' ).data( 'iterator' );
    						txt = txt.replace( '{#}', ( rowindex + 1 ) );
    					}
    				}
    				if ( txt ) {
    					$this.text( txt );
    				}
    			});
    		};
    		var replaceOnKeyUp = function( evt ) {
    			var $this = $( evt.target );
    			var id = 'title';
    			if ( evt.target.id.indexOf(id, evt.target.id.length - id.length) !== -1 ) {
    				$this.parents( '.cmb-row.cmb-repeatable-grouping' ).find( '.cmb-group-title' ).text( $this.val() );
    			}
    		};
    		$box
    			.on( 'cmb2_add_row cmb2_remove_row cmb2_shift_rows_complete', replaceTitles )
    			.on( 'keyup', replaceOnKeyUp );
    		replaceTitles();
    	});
    	</script>
    	<?php
    }
    

    Do you see something that is incorrect?

    dkurth

    (@dkurth)

    I have an example of working with custom tables…it is working GREAT!

    https://gist.github.com/dskurth/d56744de4ae076c417f59b2a459eaf4b

    Thread Starter dkurth

    (@dkurth)

    Perfect!

    Since I already have built in the software my own sanitize_text_field and the equivalent for the email and URL’s: filter_var($Record[‘link’], FILTER_SANITIZE_URL); and
    filter_var($Record[’email’], FILTER_SANITIZE_EMAIL);

    This should help! Thanks!!

    Thread Starter dkurth

    (@dkurth)

    I will check that out and get back to you. It is certainly no problem with not required fields. I was just wondering if NO fields would be display initially.

    Thread Starter dkurth

    (@dkurth)

    Michael – as I promised you, here is a subset of the code that is working beautiful using independent tables and direct storage methods.

    I create a demo file for those who want to see how to do this process of independent table data and how to get around issues. Although, for security reasons, I removed a piece of the code that shows how not to hit the database over and over again on the data upload to fields process (cmb2_override_meta_save) and changed many of the variables names. It is for demonstration purposes anyway.

    Thanks for your assistance.

    https://gist.github.com/dskurth/d56744de4ae076c417f59b2a459eaf4b

    Thread Starter dkurth

    (@dkurth)

    As an example. This is my test code. Nothing is skipping:

    add_filter('cmb2_override_meta_value', 'mmd_get_methods_custom_data', 10, 4);
    function mmd_get_methods_custom_data( $dont_override, $object_id, $args, $cmb2_field_object )
    {
    $Records = array();  
    $Record[0] =  array( 'title' => 'This is a method for the US and AUS',
    	                     'SubsName' => '',
    						 'address' => 'TEST ADDRESS',
    						 'city'=> 'testing city',
    						 'postcode'=> '90065',
    						 'latitude'=> '001.01',
    						 'longitude'=> '001.01',
    						 'phone'=> '+1-818-919-2533',
    						 'email'=> '[email protected]',
    						 'payername'=> '1',
    						 'useraccid'=> '1',
    						 'paymentdate'=> '1997-10-21',
    						 'transactionid'=> '000',
    						 'link'=> 'linkedin1.com',
    						 'facebook'=> 'facebook1.com',
    						 'twitter'=> 'twitter1',
    						 'instagram'=> 'instagram1.com',
    						 'googleplus'=> 'googleplus1.com',
    						 'linkedin'=> 'linkedin1.com',
    						 'yelp'=> 'yelp1.com',
    						 'bizdesc'=> 'business descript 1',
    						 
    						  );
    $Record[1] =  array( 'title' => 'TITLE 2',
    	                     'SubsName' => '',
    						 'address' => 'TEST ADDRESS 2',
    						 'city'=> 'testing city 2',
    						 'postcode'=> '90065-2', 
    						 'latitude'=> '002.02',
    						 'longitude'=> '002.02',
    						 'phone'=> '+2-818-919-2533',
    						 'email'=> '[email protected]',
    						 'payername'=> '2',
    						 'useraccid'=> '2',
    						 'paymentdate'=> '1998-10-21',
    						 'transactionid'=> '002',
    						 'link'=> 'linkedin2.com',
    						 'facebook'=> 'facebook2.com',
    						 'twitter'=> 'twitter2',
    						 'instagram'=> 'instagram2.com',
    						 'googleplus'=> 'googleplus2.com',
    						 'linkedin'=> 'linkedin2.com',
    						 'yelp'=> 'yelp2.com',
    						 'bizdesc'=> 'business descript 2',						 
    						 );
    
    $Records[] = $Record[0];
    $Records[] = $Record[1];
    
    	
    return $Records;		
    }
    
Viewing 15 replies - 151 through 165 (of 184 total)