The contact and comment modules set the 'user-info-from-cookie' class on the contact and comment forms. Drupal.behaviors.fillUserInfoFromCookie() in form.js looks for this class and automatically prefills the form with information from the.
However, contact module does not include form.js. I'm not sure whether modules are supposed to include this explicitly like the user and node modules do. It is included by form_process_fieldset() in form.inc but only if the form contains a fieldset? Looks a bit weird.
Comment module does include form.js but the field names used by the module (e.g. field_homepage) does not match those used by form.js (just homepage).
Comment | File | Size | Author |
---|---|---|---|
#59 | 749748-user-info-59.patch | 6.07 KB | penyaskito |
#58 | 749748-58-d8.patch | 6 KB | penyaskito |
Comments
Comment #1
sunCount me +1 for auto-loading form.js for all forms by default.
Comment #2
mavimo CreditAttribution: mavimo commentedattached patch autoload misc/form.js into theming phase of each form. I inject JS into theme_form to add JS only for web request (drupal_get_form(...) can also be used to populate info from webservice, ...)
Comment #3
sunThat needs to be [#attached][js] for the 'form' element type instead, defined in system_element_info(). See
http://api.drupal.org/api/function/system_element_info/7
http://api.drupal.org/api/function/drupal_process_attached/7
We also probably want to remove all or at least most manual loading of form.js throughout core. Watch out for the weight being used everywhere.
Comment #4
Dave ReidRe-rolled to use system_element_info. Also found all instances where we're manually loading misc/form.js and removed them since they're now covered by the attached js.
Comment #5
sunThanks!
Comment #6
Dries CreditAttribution: Dries commentedGood catches, committed to CVS HEAD. Thanks!
Comment #7
webchickThis patch seems to have broken the teaser splitter, the input format collapsing thing, and vertical tabs on the node/add form.
Re-tried from fresh install, same thing. Credits to merlinofchaos for tracking down the source of the problem.
Comment #8
webchickIncidentally, the error from Firebug is:
this.summary.html(this.fieldset.drupalGetSummary()); is not a function in vertical-tabs.js line 132
<merlinofchaos> 10:39 webchick: My guess is that it changes the order of the javascript files
My guess is, he is right. :) Can someone take a look?
Comment #9
hefox CreditAttribution: hefox commentedmisc/form.js doesn't get included at all now.
(Edit: should have read the full issue before commenting u.u failfox).
Comment #10
geerlingguy CreditAttribution: geerlingguy commentedI took a glance at the problem, and couldn't fix it - getting same error as webchick:
Comment #11
hefox CreditAttribution: hefox commentedthe issue being that
$form['#attached'] is not empty before this is called for some form; node form has Array ( [css] => Array ( [0] => modules/field/theme/field.css ) ) .
Comment #12
hefox CreditAttribution: hefox commentedI'm really not sure if this is the correct way to fix this though; moves it out of element_info and adds it in if hasn't been added in
Comment #13
geerlingguy CreditAttribution: geerlingguy commentedI can confirm that hefox's patch in #12 fixes the issue for me...
Comment #14
catchInsure should be Ensure.
Why do we need to check if (empty) before adding it - if we always want to add it indiscriminately I don't think it matters if we overwrite it.
Comment #15
Dave ReidUgh, we really need a good array_merge_recursive function that doesn't destroy on when arrays have the same keys.
Comment #16
hefox CreditAttribution: hefox commentedUpdating comment to mention why the empty check and Insure => Ensure; for the (likely very rar)e case a form wants to define it with a different weight.
Comment #17
sunRe-considered. We need to revert this, since we needlessly load jquery.js and form.js on all pages containing any form now. Which includes a simple search form that may be visible on all pages. Sorry for supporting the wrong direction.
1) Stray @todos in this patch.
2) c912374915 mentioned a cookie to form field name mismatch in the comment form that prevents the auto-population of form values. Not investigated for this patch.
Comment #18
webchickI rolled back #4 to get us out of the "critical" level of this issue. Setting needs work for sun's todos in #17, and for fixing the original bug.
Comment #19
sunRe-rolled without @todos. Node and user admin listing pages need to be tested manually.
I'm not able to see the mentioned field name mismatch in the comment form. The cookie key is "homepage", the form input name is "homepage".
Thus, if aforementioned listing pages don't produce any JS errors, this patch should be good to go.
Comment #20
sunSomeone needs to (manually) confirm that this patch works. This functionality cannot be verified by the testing framework yet.
Comment #21
sun.
Comment #22
sunActually, that's what hook_library() is for.
Comment #23
sunAlthough badly needed, this is D8 material according to the rules (I had to learn today). It may be backported at a later point in time (though that's unlikely).
Comment #24
Dave ReidNote that I'm perfectly willing to even set this to postponed until after 7.0 release, but since this is an actual non-API-changing bug report, I'm marking this back to 7.x.
Comment #25
moshe weitzman CreditAttribution: moshe weitzman commentedthen should this be #attached['library'] instead?
Comment #26
moshe weitzman CreditAttribution: moshe weitzman commentedComment #27
Bès CreditAttribution: Bès commentedHi, here a patch for D8 without cookie.
Will try to submit a D7 version soon.
Comment #28
nod_Nice (re)start.
Since we can use funky array methods I'd refactor the code a bit to remove all the for(). Also update the way .once is used to be more in line with what we're doing in the rest of core.
Comment #29
Bès CreditAttribution: Bès commentedUpdated patch.
Comment #30
Bès CreditAttribution: Bès commentedFixing coding standard for variable name and try to not modify field with data.
I'm not really happy with the explicit usage of 'name'. Maybe I can fill an attribute with the default value and test that instead ?
<input type="text" id="edit-name" name="name" data-default-value ="Anonymous" value="Anonymous" size="30" maxlength="60" class="form-text">
Comment #31
Bès CreditAttribution: Bès commentedHere is the D7 patch. I started / rerolled from the sun #22 patch.
Comment #32
Bès CreditAttribution: Bès commentedD8 version with no explicit usage of specific field name.
Comment #33
nod_For readability sake can you put
($element.val() === '' || ($element.attr('data-drupal-default-value') === $element.val()))
in a variable and use the variable in the if?Also replacing the class
.user-info-from-browser
by a data attribute to select in JS? Otherwise Butch will not be happy with you :pComment #34
Bès CreditAttribution: Bès commentedMaking Butch happy
Comment #35
Bès CreditAttribution: Bès commentedMaking HTML5 happy now
Comment #36
Bès CreditAttribution: Bès commentedAnd making nod_ happy !
Comment #37
nod_All good now everyone is happy and work as expected for comments, new account and contact page :)
Comment #38
nod_testbot
Comment #39
nod_Comment #40
alexpottThis looks good but I think we need to change record to cover the changes.
Comment #41
penyaskitoCreated change record draft: https://drupal.org/node/2243627
Comment #42
nod_Patch still works and applies. Change record is ok.
Comment #43
penyaskitoComment #44
penyaskitoAlexpott asked to add before-after examples in the change record and I did that. After another review, found the next issue:
I guess it lacks here the
$form['#attached']['library'][] = 'core/drupal.form';
?I want to review that the register form actually works, will get back to it later today.
Comment #45
penyaskitoI didn't found where it is added, but it is definitely there and works, so back to RTBC.
Comment #46
penyaskitoComment #47
penyaskitoRetitled for mentioning concrete forms instead of modules, and for clarifying that it is in the browser, not a cookie anymore.
Comment #48
Bès CreditAttribution: Bès commentedThank you penyaskito for the change record. I would like to add some clarification, but not sure if I have to edit the change record or not, so I add it here.
It's about how to use it in our form. Currently it works only for the following named input 'name', 'mail', 'homepage'
Comment #49
penyaskitoOf course you can edit it. Any clarifications are welcome :)
Please go ahead, and thanks for checking it!
Comment #51
Bès CreditAttribution: Bès commented36: 749748-36-d8.patch queued for re-testing.
Comment #52
Bès CreditAttribution: Bès commentedTestbot was failling, tests are ok now
Comment #54
penyaskitoStraight reroll.
Comment #55
tim-e CreditAttribution: tim-e commentedCan we inject this?
Comment #56
larowlanAlso there's a call to user_cookie_save() in MessageForm::save() that can be removed here I believe, using local storage instead.
Comment #57
tim-e CreditAttribution: tim-e commentedComment #58
penyaskitoRerolled manually, no interdiff provided, sorry.
@tim-e: Changed that. No need to inject, it is already injected in HEAD.
@larowlan: Removed user_cookie_save().
Comment #59
penyaskitoAuto-merged, didn't apply.
Comment #60
larowlan+1 RTBC - over to nod_ for one last look at JavaScript
Comment #61
nod_This works as expected on contact page.
The comment page has an other urelated issue:
This is never true. Changes to comment settings on the content type are not being saved properly.
When the code enters the if, everything works as expected. I'm putting this RTBC and a followup will be needed for comment field configuration saving (if it's not my setup the problem).
Comment #62
alexpottCommitted 5afbef9 and pushed to 8.0.x. Thanks!
@nod_ looks like we might not have test coverage...
Comment #64
larowlanOpened #2318251: Make comment links functionality testable and convert CommentLinkTest to PHPUnit for #61, #62
Comment #66
YesCT CreditAttribution: YesCT commentedThe change record for this is still in draft state.
(See #42 and #48.)
Comment #67
Bès CreditAttribution: Bès commentedI've already add my remark from #48 in the change record, i don't know what i need to do now. Should I publish the change record myself or maybe penyaskito or nod_ should do it ?
Comment #68
jhedstromI published the change notice.