Support Forum » User Profile

Forum Replies Created

Viewing 15 posts - 46 through 60 (of 61 total)
  • Author
    Posts
  • in reply to: Only auto populate neighborhood field if not empty #13277
    pluginovenpluginoven
    Participant

    Two weeks and crickets... The following changes would need to be made to include the
    'bind_if_empty' => false, //default true
    idea described above.

    File: js/mp-geo.js
    Line: 85

    var $this = $( this ),
        dataBinding = $this.data( 'binding' ),
        dataBindEmpty = $this.data( 'bind_if_empty' ),
        addressField = $this.data( 'address_field' ),
        fieldValue = that.getFieldData( dataBinding, place );

    File: inc/class-meta-box-geolocation.php
    Line: 97

    $binding = isset( $field['binding'] ) ? $field['binding'] : $this->guessBindingField( $field['id'] );
    $bind_if_empty = isset( $field['bind_if_empty'] ) ? $field['bind_if_empty'] : 1;
    $address_field = isset( $field['address_field'] ) ? $field['address_field'] : '';
    
    if ( $binding ) {
                $begin .= '<script type="html/template" class="rwmb-geo-binding" data-binding="' . esc_attr( $binding )
                . '" data-bind_if_empty="' . esc_attr( $bind_if_empty )
                . '" data-address_field="' . esc_attr( $address_field )
    ...

    Would be fantastically 2019 if there was a magical way to submit a pull request.

    in reply to: Only auto populate neighborhood field if not empty #13167
    pluginovenpluginoven
    Participant

    Update: I have added a working bind_if_empty. Please me know how best to submit a pull request.

    in reply to: Need a filter before save field #9005
    pluginovenpluginoven
    Participant

    It turns out the values can be easily filtered using the ´rwmb_value´ filter like so:

    add_filter( 'rwmb_value', array( $this, 'uncheck_thruthiness' ), 20, 3 );
    public function uncheck_thruthiness ( $new, $field, $old ) {
    	if($field['id'] == 'truthiness' && !empty( $field['attributes']['mod_lock'] ) ){
    		$new = '';
    	}
            return $new;
    }

    I have a different issue now... This can be marked as resolved. I'll open a new thread.

    pluginovenpluginoven
    Participant

    Issue can be marked as resolved.

    pluginovenpluginoven
    Participant

    Here are the full selectomatic custom field extended classes based on the Select field:

    if ( class_exists( 'RWMB_Field' ) ) {
    	class RWMB_Selectomatic_Field extends RWMB_Select_Field {
    		public static function walk( $field, $options, $db_fields, $meta ) {
    			$attributes = self::call( 'get_attributes', $field, $meta );
    			$walker     = new RWMB_Walker_Selectomatic( $db_fields, $field, $meta );
    			$output     = sprintf(
    				'<select %s>',
    				self::render_attributes( $attributes )
    			);
    			if ( false === $field['multiple'] ) {
    				$output .= $field['placeholder'] ? '<option value="">' . esc_html( $field['placeholder'] ) . '</option>' : '';
    			}
    			$output .= $walker->walk( $options, $field['flatten'] ? - 1 : 0 );
    			$output .= '</select>';
    			$output .= self::get_select_all_html( $field );
    			return $output;
    		}
    	}
    
    	class RWMB_Walker_Selectomatic extends RWMB_Walker_Select {
    
    		public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    			$label  = $this->db_fields['label'];
    			$id     = $this->db_fields['id'];
    			$meta   = $this->meta;
    
    			if($depth){
    				$output .= sprintf(
    					'<option value="%s" %s>%s</option>',
    					esc_attr( $object->$id ),
    					selected( in_array( $object->$id, $meta ), true, false ),
    					esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object )
    					)
    				);
    			}
    			else{
    				$output .= sprintf(
    					'<optgroup label="%s">',
    					esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object )
    					)
    				);
    			}
    		}
    
    		public function rwmb_end_html_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    			if(!$depth){
    				$output .= '</optgroup>';
    			}
    		}
    	}
    }
    pluginovenpluginoven
    Participant

    Uggg... again with the markdown. Please wrap that last code in proper backticks.

    pluginovenpluginoven
    Participant

    I was able to achieve something building off of the standard select field. I created a new field type called: 'selectomatic' which is defined as so:

    array(
        'type'    => 'selectomatic',
        'id'      => 'animal_select',
        'name'    => 'Animals',
        'options' => array(
            array( 'value' => 'monkey', 'label' => 'Monkeys' ),
                array( 'value' => 'king_kong', 'label' => 'King Kong', 'parent' => 'monkey' ),
                array( 'value' => 'curious_george', 'label' => 'Curious George', 'parent' => 'monkey' ),
            array( 'value' => 'donkey', 'label' => 'Donkeys' ),
                array( 'value' => 'eeyore', 'label' => 'Eeyore', 'parent' => 'donkey' ),
                array( 'value' => 'guss', 'label' => 'Gus', 'parent' => 'donkey' ),
        ),
        'flatten' => false
    ),

    Then I extended the Select Field Class and Select Walker Class like so:

    class RWMB_Walker_Selectomatic extends RWMB_Walker_Select {
    
    		public function start_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    			$label  = $this->db_fields['label'];
    			$id     = $this->db_fields['id'];
    			$meta   = $this->meta;
    			
    			if($depth){
    				$output .= sprintf(
    					'<option value="%s" %s>%s</option>',
    					esc_attr( $object->$id ),
    					selected( in_array( $object->$id, $meta ), true, false ),
    					esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object )
    					)
    				);
    			}
    			else{
    				$output .= sprintf(
    					'<optgroup label="%s">',
    					esc_html( RWMB_Field::filter( 'choice_label', $object->$label, $this->field, $object )
    					)
    				);
    			}
    		}
    
    		public function rwmb_end_html_el( &$output, $object, $depth = 0, $args = array(), $current_object_id = 0 ) {
    			if(!$depth){
    				$output .= '</optgroup>';
    			}
    		}
    	}

    It's not beautiful, but it's a work-around that... works!

    pluginovenpluginoven
    Participant

    Update: there seems to be a special field type (not in the documentation, by the way) called a 'select-tree' that was brought up in this thread: https://support.metabox.io/topic/custom-select-tree/

    Seems like a better starting point then the standard select field....

    pluginovenpluginoven
    Participant

    Thank you for fixing the link in the initial post. Should read:
    There is currently no support for the <optgroup> tag in the Select and Select-Advanced field types...

    pluginovenpluginoven
    Participant

    Looks like I missed the closing a tag on the link to optgroup. Sorry, wish I could edit, but that's not possible.

    in reply to: Using Custom Attributes from rwmb_before_save_post action #8929
    pluginovenpluginoven
    Participant

    Anh, that worked perfectly! Thank you, thank you, thank you. You can close this issue as resolved. But please don't forget to add this to the documentation... it will save the next person some grey hairs :D.

    in reply to: Using Custom Attributes from rwmb_before_save_post action #8927
    pluginovenpluginoven
    Participant

    HA! I was actually just in the process of modifying filter.php in a similar way.
    Does it make sense to also add a rwmb_before_save_field?
    It looks like the values would have already been saved to the default meta_keys in the dB by the time this filter is triggered.

    Regardless, thank you! I was sure I had missed something.

    in reply to: Using Custom Attributes from rwmb_before_save_post action #8925
    pluginovenpluginoven
    Participant

    At this point it seems the only way currently to 'filter' the save process using a fields custom attributes would be to create a series of new custom fields types. These new 'extended' field types would only serve to overwrite the static save method as shown above. There must be a better way to do this.

    in reply to: Using Custom Attributes from rwmb_before_save_post action #8921
    pluginovenpluginoven
    Participant

    Update!

    A little deeper and some progress.
    I have been able to extend a certain field type like so:

    if ( class_exists( 'RWMB_Field' ) ) {
    	class RWMB_Monkey_Field extends RWMB_Text_Field {
    		public static function save( $new, $old, $post_id, $field ) {
    			$pre = '';
    				if(!empty($field['attributes']['mod_lock'])){
    					$pre = 'pending_';
    				}
    
    				if($new !== $old){
    					$storage->update( $post_id, $pre.$field['id'], $new);
    				}
    
    				if( empty($new) ){
    					$storage->delete( $post_id, $pre.$field['id'] );
    				}
    		}
    	}
    }

    However this would require extending every single field type that is in use. Is there not a way to extend the base RWMB_Field class to use a special save function?

    Any clue is greatly appreciated...

    in reply to: Suppress Error Message before Meta-Box-Groups is Activated #2636
    pluginovenpluginoven
    Participant

    This is what I ended up doing:
    I include the meta-box file only if the plugin is activated like so:

    if ( is_plugin_active( 'tmeta-box-group/meta-box-group.php' ) ){
    	include ('inc/config-meta-boxes.php');
    }
    

    NOTE: the folder is now tmeta-box-group (not sure when this changed) and NOT meta-box-group.

Viewing 15 posts - 46 through 60 (of 61 total)