[wp-hackers] jQuery UI Sortable in widget admin interface

Jeremy Hough jeremy at digitalbrands.com
Mon Apr 23 14:30:03 UTC 2012


Thanks for your reply, Nathaniel.

I had already enqueued it similarly, but since these things can be 
easily caused by minor errors, I went ahead and swapped my enqueueing 
code out for yours.

I am experiencing the same end result as before: The list-items in my 
unordered list are not sortable, but event actions I write for the 
sortable instance are executed.

To give an example of some of the PHP involved, I have a standard widget 
extending WP_Widget, and the admin-interface form section has the 
following code generating the relevant markup:

<ul id="sortable">
<?php
$users = get_users();
foreach( $users as $user ) {
?>
<li><?php echo $user->{"display_name"}; ?></li>
<?php
}
?>
</ul>

I have the enqueue code declared separately, outside of the class file.
Viewing the page, I am able to see the enqueued javascript, which is 
loaded after its jquery/jquery-ui related dependencies (--with the 
enqueue code you provided, the page has the script tags printed in the 
same order).

I'm not quite sure what is causing this to not be sortable. If any other 
code snippets would be helpful, I can send those as well.

Thanks,

Jeremy Hough
> Message: 3
> Date: Fri, 20 Apr 2012 14:59:38 -0700
> From: Nathaniel Taintor<goldenapplesdesign at gmail.com>
> Subject: Re: [wp-hackers] jQuery UI Sortable in widget admin interface
> To:wp-hackers at lists.automattic.com
> Message-ID:
> 	<CAH+NfoDK_mDO=v1ECMZ7fQAddsRyFxEhxwjQvqKkZMFCopU6EQ at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Hi Jeremy,
>
> It sounds like you don't have jquery-ui-sortable properly enqueued. (The
> jquery-ui in wordpress only includes jQuery UI-core; you have to also
> explicitly add jQuery-UI-sortable).
>
> Something like this should work, if your theme scripts are in
> my-theme-javascript.js:
>
> wp_enqueue_script( 'my-sortable-script',
>                              get_stylesheet_directory_uri() .
> '/my-theme-javascript.js',
>                              array( "jquery", "jquery-ui-core",
> "jquery-ui-sortable" ) );
>
>
> Hope that helps?
>
>
> Nathaniel Taintor, Designer/Developer
> *Golden Apples Design*
> http://goldenapplesdesign.com
>
> @GoldenApples | 717.434.3226
> goldenapplesdesign at gmail.com
>
>
>
> On Fri, Apr 20, 2012 at 2:39 PM, Jeremy Hough<jeremy at digitalbrands.com>wrote:
>
>> Hi all,
>>
>> I am extending a custom widget to provide a sortable list of authors. I'm
>> finding the list does not let me sort it...
>>
>> I am able to generate the markup easily enough. I have ensured the trigger
>> for the sortable method is set to run on document.ready and after
>> dependencies (jquery&  jquery-ui) have been loaded.
>>
>> To top that off, code I put in jquery-ui event handlers executes, and no
>> errors are recorded in firefox's error_console.
>>
>> I've tested the same code in a JS fiddle (http://jsfiddle.net/Mn3sv/  ),
>> and it works without any issues (as it should).
>>
>> Is there anything that would interfere with the dragging behavior for a
>> sortable in the widget page in the WP admin interface?
>>
>> Instead of dragging to sort the LI items, the text simply gets selected
>> instead. For something so simple, it is giving me a lot of trouble to get
>> working.
>>
>> Thanks for any help!
>>
>> -Jeremy Hough
>> ______________________________**_________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.**com  <wp-hackers at lists.automattic.com>
>> http://lists.automattic.com/**mailman/listinfo/wp-hackers<http://lists.automattic.com/mailman/listinfo/wp-hackers>
>>


More information about the wp-hackers mailing list