Support » Plugin: Meta Box - WordPress Custom Fields Framework » rwmb is not defined

  • Resolved Ali Ayubi

    (@ayubi)


    Hello,
    After updating to the latest version of this plugin i getting this error:

    rwmb is not defined at /wp-content/plugins/meta-box/js/select.js:22

    • This topic was modified 3 months, 2 weeks ago by Ali Ayubi.
    • This topic was modified 3 months, 2 weeks ago by Ali Ayubi.
Viewing 13 replies - 1 through 13 (of 13 total)
  • Plugin Author Anh Tran

    (@rilwis)

    Hi Ali,

    Can you please try re-installing the plugin and clearing the browser cache? The “rwmb” variable is added in the 5.0.0 version.

    codesxt

    (@codesxt)

    I’m also getting the same error with other files:
    clone.js:270:1
    date.js:68:1

    I have updated to the latest version (5.1.1) and cleared the cache many times.

    When I see the console, it seems like /meta-box/js/script.js, which defines rwmb, is being loaded AFTER many scripts (including the ones that give me the error) which might be the cause of the scripts not finding rmwb. Maybe the enqueue order has a problem. I’m not sure.

    Plugin Author Anh Tran

    (@rilwis)

    Hi @codesxt , can you please list the plugins you’re using? Yesterday, I found this bug in MB Frontend Submission and already fixed it.

    From Meta Box we are only using Meta Box and Meta Box Group. I have also developed some custom fields and pages.

    I’ve just disabled all of my custom plugins that use Meta Box functionality and the error still persists.

    Plugin Author Anh Tran

    (@rilwis)

    Hi @codesxt,

    Can you send me the code of your meta box to check? I’ve just tested with Meta Box & Meta Box group and couldn’t replicate the error.

    Here is the code that I use to add the clonable metaboxes to the corresponding Meta Box on the site:

    
    <?php
    
    if ( ! defined( 'WPINC' ) ) {
    	die;
    }
    
    add_filter( 'rwmb_meta_boxes', 'gcbti_add_tb_fields_to_tour', 20 );
    function gcbti_add_tb_fields_to_tour( $meta_boxes ) {
      foreach ( $meta_boxes as $k => &$meta_box ) {
        if ( isset( $meta_box['id'] ) && 'tour_default_details' == $meta_box['id'] ) {
          array_push(
            $meta_box['fields'],
            array(
              'name'         => 'Travel Builder Services',
              'id'           => "_tour_tb_services",
              'desc'         => 'Ingrese el Service ID de Travel Builder',
              'placeholder'  => 'Ingrese el ID',
              'type'         => 'tb-services-list',
              'service_type' => 'tour',
              'clone' => true,
              'clone_as_multiple' => true,
              'add_button' => 'Añadir otro ID'
            ),
            array(
              'name'         => 'Travel Builder Packages',
              'id'           => "_tour_tb_packages",
              'desc'         => 'Ingrese el Package ID de Travel Builder',
              'placeholder'  => 'Ingrese el ID',
              'type'         => 'tb-packages-list',
              'service_type' => 'tour',
              'clone' => true,
              'clone_as_multiple' => true,
              'add_button' => 'Añadir otro Paquete'
            )
          );
        }
      }
      return $meta_boxes;
    }
    
    Plugin Author Anh Tran

    (@rilwis)

    @codesxt, this is the code for adding 2 fields (with custom field types) to an existing meta box. And all of them don’t have group.

    Can you post the code of the original meta box?

    Do every script using Meta Box need to inject the rwmb variable now? The original metabox is created by the theme that we are using and I found that there are some Metabox customisations involved.

    Plugin Author Anh Tran

    (@rilwis)

    Yes, the “rwmb” variable essentially is enqueued before all scripts to make it available.

    I’m not sure what your case is. Can you send me a temporary admin account to check?

    https://metabox.io/contact/

    Sadly I think my client wouldn’t allow it. I’m working for someone else. I’ll ask him tomorrow anyway.

    Here I found some of the customizations that the theme has. Maybe this has to do with it since it’s not including rwmb.

    
    jQuery( function ( $ )
    {
    	'use strict';
    
    	$(document).ready(function(){
    
    		/*if ( $('#_tour_charge_child').length ) {
    			$('#_tour_charge_child').change(function(){
    				$('#_tour_price_child').closest('.rwmb-field').toggle(this.checked);
    			});
    			$('#_tour_charge_child').trigger('change');
    		}
    */
    		if ( $('input[name="_tour_repeated"]').length ) {
    			$('input[name="_tour_repeated"]').change(function(){ toggleDatePicker();});
    			toggleDatePicker();
    		}
    
    		function toggleDatePicker() {
    			var flag = true;
    			if ( $('input[name="_tour_repeated"]:checked').val() == 1 ) flag = false;
    
    			$('input[name="_tour_date"]').closest('.rwmb-field').toggle(flag);
    			$('input[name="_tour_start_date"]').closest('.rwmb-field').toggle(!flag);
    			$('input[name="_tour_end_date"]').closest('.rwmb-field').toggle(!flag);
    			$('select[name="_tour_available_days[]"]').closest('.rwmb-field').toggle(!flag);
    		}
    
    		if ( $('.ct_datepicker').length ) {
    			$('.ct_datepicker').datepicker({ dateFormat: "yy-mm-dd" });
    		}
            
    		if ( $('.has_multi_schedules').length ) {
    			$('.has_multi_schedules').change(function(){
    				var $wrapper = $(this).closest('.schedule-wrapper');
    				var $check_box = this;
    				$wrapper.find('.add-clone, .remove-clone, .schedule-header').toggle(this.checked); // hide add-clone, remove-clone, date fields
    				$wrapper.find('.rwmb-clone').each(function(index){
    					if ( index != 0 ) $(this).toggle($check_box.checked);
    				}); // hide the other schedules
    			});
    			$('.has_multi_schedules').trigger('change');
    		}
    	});
    } );
    
    Plugin Author Anh Tran

    (@rilwis)

    When this script (maybe others as well) is enqueued?

    Can you check if they’re enqueued using the rwmb_enqueue_scripts hook? Using it ensures the script is enqueued after rwmb is available.

    They were not! Making that change fixed the issue! Sorry for taking your time with this. In the end the problem was caused by the theme and not Meta Box nor my code.
    I’m really really thankful!

Viewing 13 replies - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.