Problem/Motivation

In the SEO widget, the SEO title and SEO description fields become visible only when Enable title editing and Enable description editing are disabled in:

/admin/structure/types/manage/{content-type}/form-display

However, the fields cannot be edited. Clicking them does nothing — they do not receive focus and do not allow text input.
Disabled

When the editing options are enabled, the fields do not appear at all, but the core problem is that the fields are never editable even when they are displayed.
Enabled

This makes it impossible to modify the SEO title and SEO description through the content form.

And I'm getting this error in console:

An error occurred during the execution of the Ajax response: TypeError: snippetTitle.attr is not a function
(anonymous) @ ajax.js?v=11.2.8:1145
Promise.catch
Drupal.Ajax.success @ ajax.js?v=11.2.8:1143
success @ ajax.js?v=11.2.8:586
options.success @ jquery.form.js?v=4.3.0:281
c @ jquery.min.js?v=4.0.0-rc.1:2
fireWith @ jquery.min.js?v=4.0.0-rc.1:2
E @ jquery.min.js?v=4.0.0-rc.1:2
(anonymous) @ jquery.min.js?v=4.0.0-rc.1:2
XMLHttpRequest.send
send @ jquery.min.js?v=4.0.0-rc.1:2
ajax @ jquery.min.js?v=4.0.0-rc.1:2
$.fn.ajaxSubmit @ jquery.form.js?v=4.3.0:340
Drupal.Ajax.eventResponse @ ajax.js?v=11.2.8:798
(anonymous) @ ajax.js?v=11.2.8:648
dispatch @ jquery.min.js?v=4.0.0-rc.1:2
v.handle @ jquery.min.js?v=4.0.0-rc.1:2

Steps to reproduce

  1. Install and enable the yoast_seo module.
  2. Go to: /admin/structure/types/manage/{content-type}/form-display
  3. Enable:
    Enable title editing
    Enable description editing
  4. Edit or create content for that content type.
  5. Observe that the SEO title and SEO description fields are NOT shown, you can't click them and editing is not possible.

Proposed resolution

Fix the initialization of the editable fields in js/yoast_seo.js.
The current code uses .attr(), which is a jQuery-only method.
The script does not use jQuery, so the call silently fails and contenteditable is never applied.

Replacing .attr() with the native DOM method setAttribute() solves the issue:

- snippetTitle.attr('contenteditable', 'true');
+ snippetTitle.setAttribute('contenteditable', 'true');

- snippetMeta.attr('contenteditable', 'true');
+ snippetMeta.setAttribute('contenteditable', 'true');

After this change, both fields correctly become editable when editing is enabled in the form display.

Here is patch for this.

Remaining tasks

Review and merge the patch.
Test on a clean Drupal installation with Yoast SEO only.
Confirm that no regressions occur in other parts of the widget.
Optionally add a simple test to verify the contenteditable attribute is correctly applied.

User interface changes

No visual UI changes.
The only functional difference is that the SEO title and SEO description fields become properly editable when editing is enabled.

API changes

No API changes.
Only internal JavaScript behavior is corrected.

Issue fork yoast_seo-3560779

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

  • 3560779-cannot-edit-seo Comparecompare
  • 8.x-2.x Comparecompare
  • 1 hidden branch
  • revert-411990d2 Comparecompare

Comments

drale01 created an issue. See original summary.

netgeek123’s picture

Having the same issue. The "patch" isn't working.

Where the edit fields for title and description now show:

 Bad
Snippet preview
Content analysis

When i disable editing of the title and description, the fields show as normal, just can't edit then as expected when disabled.

I applied the patch and it made no difference.

I am getting console error:

ajax.js?v=11.2.10:1145 An error occurred during the execution of the Ajax response: TypeError: snippetTitle.attr is not a function
(anonymous) @ ajax.js?v=11.2.10:1145
Promise.catch
(anonymous) @ ajax.js?v=11.2.10:1143
success @ ajax.js?v=11.2.10:586
(anonymous) @ jquery.form.js?v=4.3.0:281
c @ jquery.min.js?v=4.0.0-rc.1:2
fireWith @ jquery.min.js?v=4.0.0-rc.1:2
E @ jquery.min.js?v=4.0.0-rc.1:2
(anonymous) @ jquery.min.js?v=4.0.0-rc.1:2
XMLHttpRequest.send
send @ jquery.min.js?v=4.0.0-rc.1:2
ajax @ jquery.min.js?v=4.0.0-rc.1:2
(anonymous) @ jquery.form.js?v=4.3.0:340
(anonymous) @ ajax.js?v=11.2.10:798
(anonymous) @ ajax.js?v=11.2.10:648
dispatch @ jquery.min.js?v=4.0.0-rc.1:2
(anonymous) @ jquery.min.js?v=4.0.0-rc.1:2
trigger @ jquery.min.js?v=4.0.0-rc.1:2
(anonymous) @ jquery.min.js?v=4.0.0-rc.1:2
each @ jquery.min.js?v=4.0.0-rc.1:2
each @ jquery.min.js?v=4.0.0-rc.1:2
trigger @ jquery.min.js?v=4.0.0-rc.1:2
(anonymous) @ jquery.min.js?v=4.0.0-rc.1:2
(anonymous) @ yoast_seo.js?v=1.x:244
(anonymous) @ yoast_seo.js?v=1.x:166
Orchestrator @ yoast_seo.js?v=1.x:104
(anonymous) @ yoast_seo.js?v=1.x:23
attach @ yoast_seo.js?v=1.x:19
(anonymous) @ drupal.js?v=11.2.10:166
(anonymous) @ drupal.js?v=11.2.10:162
(anonymous) @ drupal.init.js?v=11.2.10:32
listener @ drupal.init.js?v=11.2.10:20
drale01’s picture

I tested the patch again, and I can confirm it works correctly when applied locally. I downloaded the patch file from drupal.org and saved it to a local patches/ directory, then configured it in composer.json to use the local file path instead of the remote URL.

When I tried using the patch directly from the drupal.org URL, it didn't work (the URL returned a 404 error). However, when I applied the same patch file locally, it worked perfectly without any errors.

Here's what I did:

  1. Created a patches/ directory in my project root
  2. Saved the patch file as patches/yoast_seo-fix-attr-method.patch
  3. Updated composer.json to reference the local patch file:
       "patches": {
           "drupal/yoast_seo": {
               "Fix editable fields initialization": "patches/yoast_seo-fix-attr-method.patch"
           }
       }
  4. Ran composer update drupal/yoast_seo

The patch applied successfully and the SEO title and description fields are now editable as expected. The issue seems to be with accessing the patch file directly from the drupal.org URL, but using a local copy works fine.

stsharp’s picture

We are having this problem as well. We are running Drupal 11.3.2. I would like to note we were testing this module back in July and it worked fine. We didn't work on it for a few months and i started testing it again in late November and this is when I first noticed this problem. Has anyone gotten this patch to work on this version of Drupal?

borisr made their first commit to this issue’s fork.

borisr changed the visibility of the branch revert-411990d2 to hidden.

borisr’s picture

StatusFileSize
new732 bytes

I ran into the same issue as well. I tried applying the patch, but I hit the same problem as drale01. Instead, I applied the changes manually (and can confirm they work) and generated a new patch.

Note: I also created an issue fork, but I accidentally pushed the changes directly to the default 8.x-2.x branch. It looks like I can’t revert that now. The 3560779-cannot-edit-seo branch contains the correct updates (the same changes as in the patch).

drale01’s picture

I can confirm that patch works correct locally on Drupal 11.3.2.

anruether’s picture

Patch in #7 fixes also #3537343: Javascript error for me.