0

I want to implement a feature which, if I were to enter a correct value into a entity reference field in add node, the form will automatically update its' field values to be the same as the ones of the entity I selected (I pick what's loaded to what field).

I'm aware that hook_form_alter can alter the content of the add node form (but on load of the form), but I'm unsure which hook to use that'd trigger when I enter a correct entity reference value into the field.

  • Entering an entity is a client-side operation, there is no (server-side PHP) hook for that. I would start with adding a button to which you add an ajax callback that then does something, but this won't be trivial. And you could then expand by triggering the button automatically in JS if something is entered, but triggering something like that in JS is challenging, it's just a text field and it is valid to just type the name of the reference. Maybe when the field loses focus – Berdir Feb 27 '18 at 23:35
  • Darn. That sounds like it would be a lot of effort to put into a development of a feature that provides only visual feedback to the users. – solaris Feb 28 '18 at 0:12
  • There's a module for Drupal 7, is this the sort of thing you're after? drupal.org/project/entityreference_autofill No release for D8 yet. – imclean Feb 28 '18 at 3:59
  • Yes, but sadly it's for D7 and I'm using D8. I'm currently thinking of a different implementation. – solaris Feb 28 '18 at 19:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.