This patch automatically populates the Administer E-mail Address during install to match the Site E-mail Address. Since in most cases, these two emails will be the same, it might help to make the second field automatically take the value of the first after it has been filled out.
This task is done by adding a 'copyFieldValue' behavior to system.js. It could potentially be used elsewhere if we found a purpose for it. Here's an example of how to use it:
drupal_add_js(
array('copyFieldValue' => array(
// The primary field Id that will be filled out.
'edit-site-email' => array(
// An array of field Ids that will receive the value of the primary field.
'edit-admin-email',
'edit-some-other-id',
),
), 'setting');
Similar code is added to install.php to add the behavior to the Admin and Site e-mail fields.
Comments
Comment #1
dries commentedI've tested the patch and it works like a charm. It's a nice little addition to the installer.
- The English is in de Javascript documentation is not 100%. There seems to be a verb missing. Also, we write administrator instead of admin. Thanks. ;-)
- For bonus points, it would be nice if you sprinkled a code comment or two in the Javascript (although it is pretty readable). It think the code might be slightly more readable if the fields where called sourceField and targetField(s).
Comment #2
ChrisKennedy commented+1 - this would indeed be handy. Settings to CNW per Dries' comments.
Comment #3
quicksketchHere's a patch that names our variables 'sourceIds', 'targetIds', 'sourceField', and 'targetField'. Corrected grammatical problems and added a few bonus comments in the javascript code. :D
Comment #4
dries commentedThanks for following up on this, Nate. I looked at the new version and it looks great. Committed this little gem to CVS HEAD. Thanks.
Comment #5
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.
Comment #6
cha0s commentedThis is a great patch, but it will fail if any user adds their own entry to Drupal.settings.copyFieldValue.
This appears to be because the function() inside the bind call acts as a closure, getting access to targetIds. The problem is, the function only has access to what targetIds was set at the last iteration of the for (var sourceId in Drupal.settings.copyFieldValue) loop. The targetIds variable should be evaluated at the time the event fires instead, using this.id as the index into Drupal.settings.copyFieldValue.
Patch follows:
Comment #7
dave reidComment #8
cha0s commentedEcho echo echo echo echo! :)
Comment #9
thedavidmeister commentedThis has to be a duplicate of some issue somewhere as D8 does this already.
Comment #10
thedavidmeister commented