Story: I have three content types. Category Project Tasks I have "Project Manager" field on Project content type, which is an entity referrer field. On Task content type i have three fields Category Project Project Manager

Requirement: i need to auto fill Category and Project Manager field when i select Project.

  • Followed the same.did few changes like. i add js file in .info file and the js files is in my theme directory.code for js is as follows. (function($) { Drupal.behaviors.bartikCopyFieldValue = { attach: function (context, settings) { // Repeat this for all fields as needed $('#edit-field-sub-project-und', context).on('change', function(){ alert("hello"); // above you can use change instead of blur if element is not changed by another js }); // end of "repeat this" } }; })(jQuery); Bartik is my theme name. – Drupal Developer Jul 8 '14 at 17:13
  • It would be better to attach the js to the form, as in the linked answer, because you only need it when the form is loaded. If you add it in the .info file it gets loaded on every page. – Ollie Jul 8 '14 at 17:17
  • function bartik_form_alter(&$form, &$form_state, $form_id) { $path = drupal_get_path('thtme', 'bartik'); $form['#attached']['js'][] = $path . '/js/copy_field_value.js'; } Thats how i m attaching now, but js file is not loading when i open the form. – Drupal Developer Jul 8 '14 at 17:20
  • There's a typo: ... drupal_get_path('thtme', ... – Ollie Jul 8 '14 at 17:43
  • :) i checked by correcting it..but still the same.. – Drupal Developer Jul 8 '14 at 17:47

Browse other questions tagged or ask your own question.