Support

Account

Forum Replies Created

  • 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 sortor 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.

Viewing 1 post (of 1 total)