Disable select option

Support MB Conditional Logic Disable select option

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #6108
    woorisewoorise
    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.

    #6110
    Tan NguyenTan Nguyen
    Participant

    Dear woorise,

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

    Best,

    Tan

    #6111
    woorisewoorise
    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 NguyenTan 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
    woorisewoorise
    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
    funkatronicfunkatronic
    Participant

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

    #6170
    funkatronicfunkatronic
    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
    funkatronicfunkatronic
    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
    woorisewoorise
    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
    funkatronicfunkatronic
    Participant

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

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