Skip Navigation

[Resolved] Jquery error in wp types beta version

This thread is resolved. Here is a description of the problem and solution.

Problem:

Use https://jqueryui.com/sortable/ in wp-admin in edit post

With wp types beta version plugin, there are some jquery error and because of that my ui sortable is not working.

Here is the custom codes:
https://toolset.com/forums/topic/jquery-error-in-wp-types-beta-version/#post-627627

Solution:

the problem is in the "foreach" loop, please modify these codes from:

foreach($lessonids as $lessonid){
    echo '<ul id="sortable">';
    echo '<li class="ui-state-default">'.get_the_title($lessonid->child_id)."</li>";
    echo '</ul>';
}

To:

echo '<ul id="sortable">';
foreach($lessonids as $lessonid){
    echo '<li class="ui-state-default">'.get_the_title($lessonid->child_id)."</li>";
}
echo '</ul>';

And test again.

Relevant Documentation:

https://jqueryui.com/sortable/

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by vimalS 6 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#627343
Screenshot_5.png
Screenshot_4.png

I am trying to use : hidden link in wp-admin in edit post

Link to a page where the issue can be seen:hidden link

I expected to see working ui sortable

With wp types beta version plugin, there are some jquery error and because of that my ui sortable is not working.
Please check attached screen shot.

#627610

Hello,

I assume you are using custom codes to build your ui sortable in the wordpress admin side, which is not compatible with beta version of Types plugin.

If it is, please describe detail steps to duplicate same problem:
How do you setup the ui sortable in the wordpress admin side?
How can I see the screenshot you mentioned above:
hidden link

I need to duplicate same problem and debug it in my localhost.

In the mean time, since it is a custom codes problem, according to our support policy:
https://toolset.com/toolset-support-policy/
We cannot produce custom code solutions for you. When you need custom coding which extends Toolset functionality, we recommend contacting one of Toolset certified consultants:
https://toolset.com/contractors/

#627627

Yes, I am doing custom code for ui sortable. Let me explain you.
I have added below code in functions.php file

//enqueue scripts and style in wp-admin
function datatable_assets($hook) {
    if( $hook != 'post.php' ) 
		return;
    //enqueue css files
    wp_enqueue_style('reorderscss', get_stylesheet_directory_uri() . '/css/jquery-ui.css');
    
    //enqueue js files
    wp_enqueue_script('jqueryuijs',  get_stylesheet_directory_uri() . '/js/jquery-ui.js');
    wp_enqueue_script('admin_custom', get_stylesheet_directory_uri() . '/js/admin_custom.js');
  
}
add_action('admin_enqueue_scripts', 'datatable_assets');

//add metabox in edit custom post type
/**
 * Register meta box(es).
 */
function lesson_order() {
    add_meta_box('meta-box-id', __('Lesson Order', 'textdomain'), 'lesson_order_callback', 'course');
}

add_action('add_meta_boxes', 'lesson_order');

/**
 * Meta box display callback.
 *
 * @param WP_Post $post Current post object.
 */
function lesson_order_callback($post) {
    echo "Here you can set the order of the lessons in this course. The lessons will be shown in the same order on the course overview page.<br>Here comes a drag and drop box for ordering the lessons in this course.<br><br>";
    global $wpdb;
    $courseid = $post->ID;
    $table_name = $wpdb->prefix . "toolset_associations";
    
    $lessonids = $wpdb->get_results( "SELECT child_id FROM $table_name where parent_id = ".$courseid);

    foreach($lessonids as $lessonid){
        echo '<ul id="sortable">';
        echo '<li class="ui-state-default">'.get_the_title($lessonid->child_id)."</li>";
        echo '</ul>';
    }
}

//jquery for ui sortable in admin_custom.js file
jQuery(document).ready(function() {
    jQuery( "#sortable" ).sortable();
});

How can I see the screenshot you mentioned above:
hidden link
Ans : If you want see above page, Mark my next reply as private so I can provide you admin details.

Error mentioned in above screenshot is coming without my code.. As you can see there is no error related to ui sortable.
But, I suspect that because of those error coming my ui sortable code is not working..

Thanks!!

#627633

Thanks for the details, I can see the problem in your codes, the problem is in the "foreach" loop, please modify these codes from:

 
    foreach($lessonids as $lessonid){
        echo '<ul id="sortable">';
        echo '<li class="ui-state-default">'.get_the_title($lessonid->child_id)."</li>";
        echo '</ul>';
    }

To:

 
    echo '<ul id="sortable">';
    foreach($lessonids as $lessonid){
        echo '<li class="ui-state-default">'.get_the_title($lessonid->child_id)."</li>";
    }
    echo '</ul>';

And test again.

#627661

Done