• Creator
    Topic
  • #6108
    woorise
    Participant

    Hello,

    I am trying to disable (not hide) a taxonomy option when the file_upload field is empty.

    I took a look at the conditional logic plugin https://metabox.io/docs/meta-box-conditional-logic/ but it’s not clear to me if this is possible.

    I will appreciate any help. Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Author
    Replies
  • #6110
    Tan Nguyen
    Participant

    Dear woorise,

    The plugin is intended to show or hide field or meta box, it cannot disable a field.

    Best,

    Tan

    #6111
    woorise
    Participant

    Thank you for the quick respond.

    Is possible to add the “disable” property in the toggle_type option?

    If not how can I check if the file_upload is empty or not when the file_upload is change?

    I tried the following but it doesn’t work properly:

      jQuery('.rwmb-file_upload').on( 'change', function() {
    
        var uploaded = jQuery('.rwmb-media-input').val();
    
        if ( uploaded ) {
          //code here
        }
    
      });
    #6116
    Tan Nguyen
    Participant

    Dear woorie,

    Because toggle_type is affected to whole field/meta box and its container and many fields aren’t normal form input field so it isn’t possible. Sorry for that.

    #6150
    woorise
    Participant

    I see. So I need to do this manual.

    Can you please give me some info on what event is triggered when we use the “file_upload” field so I can disable/enable the select option if the user upload a file.

    I tried the code above but it doesn’t work properly.

    #6169
    funkatronic
    Participant

    Just to be sure, you want to know when files are added or removed?

    #6170
    funkatronic
    Participant

    @woorise Your solution has a flaw; you check if the result is empty by checking the length. This should work:

    
    jQuery('.rwmb-file_upload').on( 'change', function() {
        var uploaded = jQuery('.rwmb-media-input');
        if ( uploaded.length ) {
          //code here
        }
      });
    
    #6171
    funkatronic
    Participant

    I just added a new commit on GitHub. The change event now includes a second argument, which contains all of the hidden inputs. This will allow you to count them to see if any are selected:

    
    jQuery('.rwmb-file_upload').on( 'change', function( event, items) {
        if ( items.length ) {
          //code here
        }
      });
    
    #6200
    woorise
    Participant

    Thank you for your answer.

    I tried the following on a “select_advanced” field but if I first open the dropdown then it doesn’t enable the option.

    jQuery(document).ready(function(){
    
      jQuery("#status option[value='23']").prop("disabled", true);
    
      jQuery('.rwmb-file_upload').on( 'change', function( event, items ) {
    
        if ( items.length ) {
          jQuery("#status option[value='23']").prop("disabled", false);
        }
    
      });
    });
    #6206
    funkatronic
    Participant

    Can you post your code so I can experiment with what you are trying to do?

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