Home › Forums › Add-ons › Repeater Field › Disable reordering of the repeater field items › Reply To: Disable reordering of the repeater field items
Hello
I tried another way to prevent sortable feature, in my case on a flexible_content field.
I started work using this thread, which no more accepts replies.
acf.addAction( <code>ready_field/key=${fieldId.slice( -1 )}</code>, ( field ) => {
// Prevent sorting
// TODO was unable to find a way to prevent the sortable feature before starting to drag element
field.on( 'sortstop', ( e ) => e.preventDefault() )
// Target the right sort handle elements, according to each field type HTML structure
// Selectors must be precise not to disable sorting in subfield that has to keep its sortable feature
switch( field.type ) {
case 'flexible_content':
// Up to element, then down to handle
$firstMatching.closest( '.acf-flexible-content' ).find( '> .values > .layout > .acf-fc-layout-handle' )
.css( 'cursor', 'pointer' )
.attr( 'title', 'Reorder disabled' )
break
}
} )
This solution abort the sort forcing to keep same order, but not perfect since ACF field is flagged changed so leaving the page prompts to confirm change loss.
I tried to disable the feature before it begins, for instance using sortstart
event with a simple e.preventDefault()
but it ends with a JS error.
I also tried to remove sort
or ui-sortable
classes. That could work since onHoverSortable()
func in wp-content/plugins/advanced-custom-fields-pro/assets/build/js/acf-field-group.js
is testing for ui-sortable
class to initialize sortable, but a mouseover or mouseenterr event put the class back.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.