When the OpenID login link is clicked, the expected result is for the username and password fields to be hidden, and the openid field to appear.

However, if the user login block is used on the contact page, instead of hiding the username field in the user login block, the name field is hidden on the contact form.

The cause of this seems to be that the classes and ids for these fields are the same - therefore, the js doesn't know which one to pick (or picks the one that appears first in the page).

Comments

mfb’s picture

Status: Active » Needs review
StatusFileSize
new752 bytes

We should be able to fix this by adding the form ids to the selector.

c960657’s picture

StatusFileSize
new3.04 KB

There are other conflicts, e.g. #edit-name. Here is what I came up with (I did not know that somebody was already working on this).

mfb’s picture

Maybe you could also fix the nearby weird indentation (3 spaces instead of 2)?

Otherwise it looks good to me. I noticed you changed $('div.messages.error').css('display', 'block'); to $('div.messages.error').hide(); which I guess is fine, no need to show error messages after these links are clicked.

By the way, while testing the contact page I noticed that the contact edit-name input gets the error class when login fails, and likewise login edit-name input gets error class when contact name is left blank. This looks like a regression in form API with error being set for all forms on the page, I will file an issue on that if I don't find one that already exists.

c960657’s picture

StatusFileSize
new3.19 KB

This fixes the weird 3 indentation too.

c960657’s picture

Version: 7.x-dev » 8.x-dev
StatusFileSize
new2.85 KB
c960657’s picture

StatusFileSize
new2.85 KB
c960657’s picture

sun’s picture

Status: Needs review » Needs work
+++ b/core/modules/openid/openid.js
@@ -2,17 +2,21 @@
   attach: function (context) {

Overall, it looks like we're missing a $.once() here...? (as in all other Drupal behaviors - otherwise, this behavior is executed multiple times when behaviors are re-run on the existing page)

+++ b/core/modules/openid/openid.js
@@ -2,17 +2,21 @@
+    // Match the forms user-login and user-login-form (the latter is defined in
+    // user_login_block()).
+    var form = $('#user-login, #user-login-form');

1) It would make much more sense to me if openid.module would apply a .openid-form CSS class to the forms it enhances. Based on that, this behavior would be way more robust:

$('form.openid-form', context).once('openid', function () {
});
+++ b/core/modules/openid/openid.js
@@ -36,12 +40,12 @@ Drupal.behaviors.openid = {
       .click(function () {
          openidElements.hide();
          loginElements.css('display', 'block');
...
+         // Clear OpenID Identifier field and remove possible error message.
+         openidIdentifier.val('').removeClass('error');
+         $('div.messages.error').hide();
+         // Set focus on username field.
+         form.find('input[name="name"]')[0].focus();
+         return false;
       });

This looks like a typical detach behavior method to me.

9 days to next Drupal core point release.

c960657’s picture

Status: Needs work » Needs review
StatusFileSize
new3.9 KB

Thank you for good review comments.

Overall, it looks like we're missing a $.once() here...?

Similar logic is implemented via .openid-processed. I have updated it to use once() instead.

It would make much more sense to me if openid.module would apply a .openid-form CSS class to the forms it enhances.

Good point. Done.

This looks like a typical detach behavior method to me.

I'm not sure what you mean. Something like this?

-        $('div.messages.error').hide();
+        var error = $('div.messages.error');
+        if (error.size()) {
+          Drupal.detachBehaviors(error.get(0));
+          error.remove();
+        }
bfroehle’s picture

It'd be nice to agree on a common solution here, as #1395612: Conflict with core contact form in the CAS module is waiting on the outcome of this issue.

c960657’s picture

A fix for this issue is included in the patch for #1538462: Cannot log in with OpenID due to "required" attribute.

c960657’s picture

Status: Needs review » Fixed

Fixed together with #1538462.

Status: Fixed » Closed (fixed)

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