I tried the autofill and it works nice when the user is using it, but what about to autofill field when the entityreference field is pre-populated over the url with module
https://drupal.org/project/entityreference_prepopulate

This would allow, to prefill fields and user can review the values and save it.

Comments

jgullstr’s picture

Assigned: Unassigned » jgullstr

That's a good idea! I've started to look into this, but the module will need some restructuring to work. Expect a patch in a week or so.

mariusm’s picture

+1

jgullstr’s picture

Title: Support for entityrreference prepopulate module » Support for Entityreference prepopulate module
Assigned: jgullstr » Unassigned
Status: Active » Needs review
StatusFileSize
new11.6 KB

Patch provided as promised. Please try it out and let me know if it works as expected.
Note: You need to run update.php for the module to recognize prepopulate data.

mariusm’s picture

it's ok

Thanks

mariusm’s picture

if you can add a small improvement ->
ability to hide fields like prepopulate

Thanks

jgullstr’s picture

The hide field action should still work by setting it from prepopulate settings, or is it not working for you?

mariusm’s picture

In my implementation only hides the reference field.
I want to hide fields prepopulated with your module.
Thanks

jgullstr’s picture

Ah ok, sorry I missed your point. Hiding the fields populated by this module, I believe, falls outside the module's scope. I will consider options for making autofill data available for other modules in a later release, but unfortunately there is no simple way of doing this in the current version.

//Josef

jgullstr’s picture

Status: Needs review » Reviewed & tested by the community
jgullstr’s picture

Status: Reviewed & tested by the community » Fixed

Commited changes.

jgullstr’s picture

mariusm,

The latest dev version has its own $form_state array. If you need to hide the autofilled fields, it can be accomplished by implementing a form_alter in your custom module. Something along the lines of this should do it:

/**
 * Implements hook_form_alter().
 */
function YOURMODULE_form_alter(&$form, &$form_state) {
  if(isset($form_state['entityreference_autofill'], $form['#entity_type'], $form['#bundle'])) {
    // Get filled field names from form_state.
    $field_names = array_keys($form_state['entityreference_autofill'][$form['#entity_type']][$form['#bundle']]);
    // Hide fields.
    foreach ($field_names as $field_name) {
      $form[$field_name]['#access'] = FALSE;
    }
  }
}

Hope this helps.

//Josef

Status: Fixed » Closed (fixed)

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

rollingnet’s picture

see below

rollingnet’s picture

Issue summary: View changes
Status: Closed (fixed) » Active

I'm using the latest dev either of this module and prepopulate one.
When I prepopulate a form with entity reference field and then use autofill function, everything is ok, except if I make en error in the form (like leaving blank a mandatory field).
In this case, the entity reference field (that is prepopulated) becomes blank.
This not happen if I don't use the autofill function in the form, the page simple reload showing me the error and entity reference value is still here.
So I think this bad behavior is caused by this module and not by the prepopulate one.

jgullstr’s picture

That sounds odd. Can you provide a database dump demonstrating this behavior using only prepopulate and autofill?

//Josef

rollingnet’s picture

I can provide the live site where this behavior occurs:
http://www.unannoconnoi.it/node/add/modulo-iscrizione?field_evento_a_cui...
as you can see,the prepopulated one is the first one, i.e. "Evento a cui si vuole partecipare" and the autofill field is the second one, i.e. "Ricerca partita IVA".
I use the autocomplete limit length module (https://drupal.org/project/autocomplete_limit) to start autocomplete function only after 11 digits are inserted.
Try to digit this 02527661207 in the "Ricerca partita IVA" field.
You'll see that some fields t will be correctly autocompleted.
Now submit ("invia") the form without filling any other fields.
Look at the prepopulated field (the first one): it is blank now.
If you try to submit the form without autocompleting it, the first field is correctly prepopulated.

jgullstr’s picture

Does the problem disappear if you disable the autofill functionality on "Ricerca partita IVA"?

rollingnet’s picture

I can confirm that disabling the autofill functionality, the form works correctly, so the issue is in this module.

rollingnet’s picture

I think that this issue can be related to incompatibility of this module with validation from field validation module: in the form there are fields that are validated with this option checked:

X Set errors using field API
There are two methods to set error: using form_set_error provided by form api, using errors provided by field api. form_set_error does not work correctly when a sub form embed into another form. errors does not work correctly when current field does not support hook_field_widget_error.

jgullstr’s picture

Can you export the content type and its dependencies as a feature (preferably), alternatively provide a clean database dump or a step-by-step guide? I haven't been able to replicate this error (although I can see it exists from your link).

//Josef

rollingnet’s picture

I've just installed the latest dev version of Entity Reference Prepopulate and the issue above seems to be solved. So it seems it was an issue related to that modules and not to this one.

jgullstr’s picture

Status: Active » Fixed

Ok, great! Setting status back to fixed.

//Josef

Status: Fixed » Closed (fixed)

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