When adding a new content type, you can decide the menu which nodes of that content type can belong to.

After the checkboxes that allow you to select these menus, there is the "default parent item" listbox which allows you to decide the default value for the "parent item" field shown when you add a node of that content type to a menu. This listbox is always shown, even if you haven't selected any of the checkboxes representing the available menus in a Drupal site.

Instead, it should be shown/hidden dynamically based on the selection of any of the checkboxes representing the various menus.

Comments

falcon03’s picture

Title: "default parent item" should be hidden when no menu is selected » Adding a new content type, "default parent item" is shown even if any menu is selected
Issue tags: +Accessibility

Tagging + Adding a more descriptive title

falcon03’s picture

Title: Adding a new content type, "default parent item" is shown even if any menu is selected » Adding a new content type, "default parent item" is shown even if no menu is selected
falcon03’s picture

Since the same problem happens with the "field widgets" form item shown when you add a new field, I wonder if this is a more abstracted issue related to the Form API...

cb’s picture

Hiding the menu when there is nothing to display is quite easy and have just updated the menu.admin.js to do this.

However, abstracting this to the form API is something that will require a little more work.

Adding a patch for the time being.

falcon03’s picture

Status: Active » Needs review
Issue tags: +JavaScript

@Christian Biggins: oh, thank you for the patch. Let's see if the bot likes it! :-)

Also tagging.

Anyway, if we could abstract this patch it would be really great because this is an issue that happens in many different places (especially in contrib)...

mgifford’s picture

Bot liked it and it applied nicely to my local install. It's pretty simple JS, but might be good to have it reviewed especially in light of thinking about greater abstraction.

nod_’s picture

Status: Needs review » Needs work

+ $select.parents('div').first().hide();

Shouldn't that be

+ $select.closest('div');

We might want to get more specific than that for the selector. like .form-item or something.

As far as abstracting that, not sure. But we could improve the speed of this thing by not using .append in the loop. It's not really good practice to begin with.

cb’s picture

StatusFileSize
new1018 bytes

Updated patch with closest() and not parents().

I'm not sure what would be a better practice than using append()? From my reading, its not totally inefficient. Feedback appreciated.

cb’s picture

Status: Needs work » Needs review
nod_’s picture

can you put the $select.closest('div') in a variable before the if? That kind of selector duplication is a pain to refactor afterwards.

mgifford’s picture

swentel’s picture

Component: field system » menu.module

This doesn't really belong to the field system.

mgifford’s picture

cb’s picture

Now with added duplication avoidance!

mgifford’s picture

Issue tags: +Usability

This needs a JS review, but it's so very short. I've tested it in a Mac with FF, Safari, Chrome & Opera. Works as expected. I'm including a before/after shot.

I did have questions about the comments. The text will appear like this in the text:

       // Add new options to dropdown.
       // Keep a count of options for testing later.

But think this is more common.

       // Add new options to dropdown. Keep a count of options for testing 
       // later.

Heck, maybe it could even go on one line.... :)

I think this will offer usability improvements too! Looks good.

mgifford’s picture

StatusFileSize
new186.99 KB
new177.08 KB

Screenshots as promised.

attiks’s picture

Status: Needs review » Needs work
+++ b/core/modules/menu/menu.admin.jsundefined
@@ -33,13 +33,25 @@ Drupal.menuUpdateParentList = function () {
+      var parent_div = $select.closest('div')

missing ;

nod_’s picture

Also, you can use .toggle()

// Hide the parent options if there are no options for it.
$select.closest('div').toggle(totalOptions > 0);

instead of the if.

larowlan’s picture

Assigned: Unassigned » larowlan

will re-roll today

mgifford’s picture

Oh ya, I think it would be better if you also added the HTML5 hidden attribute as per:
http://www.paciellogroup.com/blog/2012/05/html5-accessibility-chops-hidd...

cb’s picture

Both hidden and aria-hidden?

larowlan’s picture

Status: Needs work » Needs review
Issue tags: +Needs manual testing
StatusFileSize
new1 KB
new1.07 KB

From the link

If you want to hide content from all users, use the HTML5 hidden attribute (along with CSS display:none for browsers that do not yet support hidden) There is no need to use aria-hidden.

Just using hidden for now.

Status: Needs review » Needs work

The last submitted patch, menu-hidden-1829328.22.patch, failed testing.

mgifford’s picture

@Christian Biggins - the recommendations I've seen suggest just using HTML5's hidden attribute. I think that provides all the semantic information & is well supported by AT.

HTML5 supersedes ARIA where they serve the same purpose.

mgifford’s picture

Status: Needs work » Needs review
Issue tags: -JavaScript, -Usability, -Accessibility, -Needs manual testing, -Needs JavaScript review

#22: menu-hidden-1829328.22.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +JavaScript, +Usability, +Accessibility, +Needs manual testing, +Needs JavaScript review

The last submitted patch, menu-hidden-1829328.22.patch, failed testing.

mgifford’s picture

I'm trying to look at this test locally, but not sure which test to find this one under:
CollapsedDrupal\system\Tests\Upgrade\BlockUpgradePathTest

The problem is with Drupal\simpletest\WebTestBase->xpath('//li[@class=:class]', Array) called by simplexml_import_dom(): Invalid Nodetype to import

But I can't get to the full results to see what the test is failing over.

mgifford’s picture

Status: Needs work » Needs review

#22: menu-hidden-1829328.22.patch queued for re-testing.

cb’s picture

Sorry for lack of response on this. Looks like its all ok?

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

Just tested the patch in #22 http://simplytest.me/project/drupal/8.x

It's working as expected.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Just to check on this bit:

        $select.append(
             $('<option ' + (machineName === selected ? ' selected="selected"' : '') + '></option>').val(machineName).text(options[machineName])
           );
+          totalOptions++;

It's not possible to test something on $select rather than keeping track of the totalOptions separately?

mgifford’s picture

If I'm here - en/admin/structure/types/manage/article

And I go to the Console in Chrome, why do I get:

> console.log(machineName);
ReferenceError: machineName is not defined

I'm just trying to see what other options there are other than incrementing a value in the loop.

solange_sari’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new73 KB

Great feature!!!
and it works properly as showed in the following picture

Menu setting testing

mgifford’s picture

Status: Reviewed & tested by the community » Needs review

Putting this back to needs review as we should address @catch's comments about totalOptions.

Thanks so much for the review @solange_sari very useful.

mgifford’s picture

mgifford’s picture

jessebeach’s picture

from #31

Just to check on this bit:

$select.append(
$('').val(machineName).text(options[machineName])
);
+ totalOptions++;
It's not possible to test something on $select rather than keeping track of the totalOptions separately?

It seems fine to keep track of the options count this way, since the var is being used as a truthy test for the toggle and attr methods.

mgifford’s picture

Status: Needs review » Reviewed & tested by the community

Ok, I'm going to set it back to RTBC then.

xjm’s picture

#22: menu-hidden-1829328.22.patch queued for re-testing.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Now we have jshint in core :)

+++ b/core/modules/menu/menu.admin.jsundefined
@@ -32,14 +32,19 @@ Drupal.menuUpdateParentList = function () {
+      $select.closest('div').toggle(totalOptions > 0).attr('hidden', totalOptions == 0);

Should be ===

Problem synopsis      JSHint: Expected '===' and instead saw '=='. (at line 47)
larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new1.01 KB
new523 bytes
andypost’s picture

Status: Needs review » Reviewed & tested by the community

Nice

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 7ba4db0 and pushed to 8.x. Thanks!

Automatically closed -- issue fixed for 2 weeks with no activity.