Disable select option
Support › MB Conditional Logic › Disable select option
- This topic has 9 replies, 3 voices, and was last updated 8 years ago by
funkatronic.
-
AuthorPosts
-
June 20, 2017 at 4:22 PM #6108
woorise
ParticipantHello,
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.
June 20, 2017 at 4:28 PM #6110Tan Nguyen
ParticipantDear woorise,
The plugin is intended to show or hide field or meta box, it cannot disable a field.
Best,
Tan
June 20, 2017 at 4:54 PM #6111woorise
ParticipantThank 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 } });
June 21, 2017 at 9:00 AM #6116Tan Nguyen
ParticipantDear 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.
June 22, 2017 at 11:23 PM #6150woorise
ParticipantI 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.
June 25, 2017 at 10:23 PM #6169funkatronic
ParticipantJust to be sure, you want to know when files are added or removed?
June 25, 2017 at 10:31 PM #6170funkatronic
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 } });
June 26, 2017 at 1:24 AM #6171funkatronic
ParticipantI 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 } });
June 28, 2017 at 7:22 PM #6200woorise
ParticipantThank 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); } }); });
June 29, 2017 at 8:22 AM #6206funkatronic
ParticipantCan you post your code so I can experiment with what you are trying to do?
-
AuthorPosts
- You must be logged in to reply to this topic.