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

dries’s picture

I'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).

ChrisKennedy’s picture

Status: Needs review » Needs work

+1 - this would indeed be handy. Settings to CNW per Dries' comments.

quicksketch’s picture

Status: Needs work » Needs review
StatusFileSize
new2.8 KB

Here'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

dries’s picture

Status: Needs review » Fixed

Thanks for following up on this, Nate. I looked at the new version and it looks great. Committed this little gem to CVS HEAD. Thanks.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

cha0s’s picture

StatusFileSize
new778 bytes

This 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:

dave reid’s picture

Status: Closed (fixed) » Needs review
cha0s’s picture

Echo echo echo echo echo! :)

thedavidmeister’s picture

Status: Needs review » Closed (duplicate)

This has to be a duplicate of some issue somewhere as D8 does this already.

thedavidmeister’s picture

Version: 6.x-dev » 8.x-dev