Pardon me if there is already an issue for this, but I tried to search first and came up with nothing.
I am kind of annoyed by the way we are saving translated strings on the translation page. And this might apply elsewhere, in which case, please provide more info. But the actual problem is this:
- I go to the "Translate interface" page to translate one specific string.
- I find it, enter some text in the translation field, and hit the save button.
- I expect the form to save, but instead there is now a notice telling me that "Changes made in this table will not be saved until the form is submitted." which in turn pushed the submission button down. Which is kind of a paradox, since I thought I just submitted the form, but the button never got clicked, because I needed to be informed about the importance of submitting. :)
Possibly best explained with a gif (as everything else in life) :). Attached
So, my rant is now over.
The problem here is that the inserting of a notice pushes the DOM down before the click is propagated to the button. Or more precisely, the event that triggers the change happens before the event that is the click. So the easy fix is the following:
- Use a small setTimeout on the showing of the notice. This way the click would be allowed to happen before we push the DOM downwards.
I have written a lot of javascript over the years, but I am not familiar with styles and guidelines (and libraries available) for Drupal core. Maybe we can utilze something there. Also, I am using a named anonymous function (for easier debugging) and _this for making sure we have the right _this. Not sure if that is within style? At least it passes eslint.
Ok. so patch coming up at least. Not just ranting
Comment | File | Size | Author |
---|---|---|---|
#11 | 2471136-11.patch | 1.65 KB | eiriksm |
#5 | 2471136-5.patch | 1.11 KB | eiriksm |
#4 | 2471136-4.patch | 1.11 KB | eiriksm |
#2 | d8-form-change-ux-after.gif | 222.45 KB | eiriksm |
#1 | 2471136.patch | 1.14 KB | eiriksm |
Comments
Comment #1
eiriksmComment #2
eiriksmAlso, since I am already advocating that everything is best explained in gifs. Here is the after gif.
I might add, that this approach makes it so that if you click the save button and hold it, your button will release when the DOM has pushed down, and the same behaviour will show itself again. You will have to click a second time.
Comment #3
googletorp CreditAttribution: googletorp commentedI believe best practice is to use the variable "that" to refer to this in a different scope.
Should be anonymous function.
Comment #4
eiriksmThanks for reviewing. Fair points.
I would argue it is somewhat a matter of taste, and of course if there is an established style, that should be followed.
In Drupal core js, it seems to be two different paradigms:
var that = this;
and
var form = this; // Or whatever _this_ would be referring to. In the case of this patch, I guess I could use var table = this;
I have also seen stuff like var self = this (in core) and formObject = this (instead of form = this). As a matter of fact, in one case, there is a file that has both "var that = this;" and then 60 lines down: "var self = this;". So best practice or style, none of them are really consistent. But point is, no occurences of _this, as I used in my patch. So that is a very good point, either way. So I changed it to "that" anyway.
Updated patch with your suggestions. Thanks again for reviewing.
Comment #5
eiriksmHeh, sorry. Was a bit quick with the changing of _this :)
Comment #6
googletorp CreditAttribution: googletorp commentedLooks good.
Comment #7
nod_unfortunately the js isn't up to core standards. let me do a proper review it needs work.
Comment #8
nod_What could be done with minimal code changes it to use debouce (or throttle really), can you try something like:
Changing
to
And that should work (a dependency on the
core/drupal.debounce
lib would need to be added as well).Comment #9
googletorp CreditAttribution: googletorp commented#8 It seems like a hack to me to use debounce for this. This is not the purpose for debounce and since debouce uses setTimeout anyways it doesn't really make any sense to me.
I have a hard time understanding why adding extra unneeded scripts and complexity should be more "up to core standards", as you put it yourself.
Comment #10
nod_You're right, it's a dirty hack. Looked into it, we should be using our custom
formUpdated
event instead ofchange
.We need to add an explicit dependency on
core/drupal.form
. The file is already there because of something else on the page so we're not adding unrelated stuff we're just being explicit about it.Changing:
$form.one('change.localeTranslateDirty', 'table', function () {});
to
$form.one('formUpdated.localeTranslateDirty', 'table', function () {});
Same for the other event below.
Comment #11
eiriksmUsing drupal/form works.
Updated patch.
Comment #12
nod_This works as expected. Thanks!
Comment #13
alexpottThis issue is a normal bug fix, and doesn't include any disruptive changes, so it is allowed per https://www.drupal.org/core/beta-changes. Committed affe3f8 and pushed to 8.0.x. Thanks!
Comment #15
tstoecklerAwesome, thanks a lot! Tagging for statistics.