Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UX] Allow a field HTML ID to be set as target in theme_token_tree_link() #4316

Open
klonos opened this issue Feb 19, 2020 · 6 comments · May be fixed by backdrop/backdrop#3118
Open

[UX] Allow a field HTML ID to be set as target in theme_token_tree_link() #4316

klonos opened this issue Feb 19, 2020 · 6 comments · May be fixed by backdrop/backdrop#3118

Comments

@klonos
Copy link
Member

klonos commented Feb 19, 2020

This issue came up as I was testing the PR for #1439. Everything was working beautifully in the PR sandbox, but only if you are an experienced Drupal/Backdrop user, and you can thus anticipate certain quirks we have all gotten used to over the years...

After having clicked the "Browse available tokens" link and browsed through the tokens, when you click on a token to be used, you get this error/prompt:

Screen Shot 2020-02-20 at 4 09 49 am

I realize that in theory, the token browser can be used in any field in the same page (although it does not necessarily mean that the token set specified in a "Browse available tokens" link for one field can be used in other fields), but it is annoying to have clicked a link under a specific field, and then have this error message telling you to select a field.

If the field had focus prior to the token browser dialog being opened, then any token clicked on the dialog gets properly inserted into that field, without any error/prompt; but if the focus was elsewhere before clicking the link (such as the "enable" checkboxes in this case, which show/hide the image alt/title fields using #states), then you get this UX WTF.

Can we have it so that theme_token_tree_link() accepts a field ID as a parameter, so that once the "Browse available tokens" link is clicked, there's some JS triggered, which sets the focus to that field before opening the token browser?

@docwilmot
Copy link
Contributor

I've got a strong feeling you've opened this issue before

@klonos
Copy link
Member Author

klonos commented Feb 19, 2020

The only somehow related one I could find @docwilmot was #3187 (was searching with "token" and "focus" as terms). Perhaps I am losing my touch and have started forgetting issues I have previously filed 😅 ...happy to close this as duplicate if we find that other issue.

@klonos
Copy link
Member Author

klonos commented Feb 19, 2020

...OK, you must be talking about #1497, but that was for a specific form/field. What I am aiming for here is for a generic way, to allow this functionality as part of theme_token_tree_link(), by specifying an ID (instead of having to add separate javascript for each field/form we have the same issue with) ...IOW, something that themers and module developers can easily implement and reuse.

So take the code bit here: https://github.com/serundeputy/backdrop/blob/1.x/core/modules/node/js/node.types.js#L117 ...move it into the System module, and make the ID selectors be variables which can be specified in theme_token_tree_link().

@quicksketch
Copy link
Member

I took a stab at implementing something that might fit the bill here: backdrop/backdrop#3118

It does not actually allow a field's HTML ID to be targetted directly. Instead any token dialog link will automatically select the first field within a "form-item" wrapper. This works in the typical situation where the token link is placed within a form element's #description property.

If no field can be found (or if no previous field was given focus), it falls back to the previous behavior of showing an alert dialog to the user.

@herbdool
Copy link

herbdool commented Jun 3, 2020

I might have been doing it wrong, or its an issue with testing on a phone, but it didn't seem to work yet. I like where it's going though.

@indigoxela
Copy link
Member

It's not only on a phone, I tested with Firefox and Chromium and it doesn't work with either.

I've been testing on these paths:

  • admin/config/urls/path/patterns
  • admin/structure/types/manage/post/fields/body

If I didn't click inside an input field before clicking the "browse tokens" link, I get the popup with "First click a text field into which...".

If I do click inside a different field, but scroll on and click on another (not nearest) token browser link, the token gets inserted into the previously clicked input field.

@jenlampton jenlampton modified the milestones: 1.18.1, 1.18.2 Jan 14, 2021
@jenlampton jenlampton modified the milestones: 1.18.2, 1.18.3 Mar 24, 2021
@jenlampton jenlampton modified the milestones: 1.18.3, 1.18.14 Apr 21, 2021
@jenlampton jenlampton modified the milestones: 1.18.4, 1.19.1 May 16, 2021
@jenlampton jenlampton modified the milestones: 1.19.1, 1.19.2 May 26, 2021
@quicksketch quicksketch modified the milestones: 1.19.2, 1.19.3 Jul 21, 2021
@jenlampton jenlampton modified the milestones: 1.19.3, 1.19.4 Aug 12, 2021
@quicksketch quicksketch modified the milestones: 1.19.4, 1.20.1 Sep 15, 2021
@quicksketch quicksketch modified the milestones: 1.20.1, 1.20.2 Oct 11, 2021
@jenlampton jenlampton modified the milestones: 1.20.2, 1.20.3 Nov 18, 2021
@quicksketch quicksketch modified the milestones: 1.20.3, 1.20.4 Dec 3, 2021
@herbdool herbdool removed this from the 1.20.4 milestone Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants