When adding a relation to a contact (redhen/contact/%/connections/add), the connection type switcher does not work properly. After making a selection in the connection type, the "New or existing..." switcher does not work correctly.

One problem is that the ajax callback redhen_relation_form_refresh() replaces the given form component with an entirely different component. Updating the return value of it to be simply return $form['fields']; can fix that aspect.

The remaining problem is in the result of choosing new or existing. We currently have two main sections of the form: the Relation part (using the form element ID of "fields"), and the added or selected entity that is on the other end of the relation (using the form element ID of "entity_info"). So when the "fields" portion is refreshed, the "entity_info" section is not updated and continues to hold the form for the wrong entity.

A couple of ideas: either moving the entity form up inside the "fields" section, or reworking the form refreshing.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

levelos’s picture

Status: Active » Postponed (maintainer needs more info)

What "new or existing" selector are you referring to? The add a connection interface does not provide the ability to create new orgs or contacts inline.

SocialNicheGuru’s picture

Status: Postponed (maintainer needs more info) » Active

I am experiencing this.

Goto a connection
Setup multiple relation types
Now add a relation at a link like /redhen/contact/3/connections/add
There is a box that allows you to enter new or existing.

When you first goto the page, contact/x/connections/add, new is selected.
When you switch between new and existing for the relation type, I am finding that it actually works.

But if you go to the top of the page and choose a different relation type, then nothing happens. Nothing is updated.

SocialNicheGuru’s picture

Is there anyway to get this fixed.
This seems to be pretty fundamental.

Possible help:
https://www.drupal.org/node/2324953

if a relation is chosen, the entire form should be updated so that both the new-existing field and a relationship attached should be updated.
In the added relationship portion only entities that are available given the current chosen relation and entity should be displayed.

ehanuise’s picture

Similar issue here with another aspect of this :
- define a contact to contact relationship type, and a contact to org relationship type
- go to a contact
- add relationship. the 'contact to org' is the default but a popup list aloows me to pick the 'contact to contact' type
- pick 'contact to contact'
- the bottom of the form does not refresh, and keeps offering me new/existing org as the target
- I have to submit empty to gen an error message and the proper form now displaying contact targets instead of org targets

anemirovsky’s picture

Status: Active » Needs review
FileSize
2.73 KB

It looks like this was broken during a refactoring of this form in https://github.com/thinkshout/redhen/commit/e95592b40d9a386452f91f06ef79.... There were a few issues here:

  1. The ajax callback 'redhen_relation_form_refresh' was being used twice for two different fields. It looks like it was co-opted for the entity type selection field, but the original use in the relation type field was not replaced with a new implementation.
  2. The original 'redhen_relation_form_refresh', even if it was still only used for the relation type selection field, no longer replaced the correct form/html elements.
  3. The form validation was validating contact/org entity fields when triggered via AJAX submit, which was causing validation errors on some fields that aren't shared across entities across the different relation types configured. I don't think we need to validate any fields when switching relation types or entities, only on actual form submit.
anemirovsky’s picture

FileSize
5.71 KB

I found a couple more problems which this update patch addresses.

  1. When switching between RedHen Orgs and RedHen Contacts, the Org/Contact type wasn't being set correctly, so the form for the entity to relate to wasn't complete.
  2. The validation for the entity to relate to was incorrectly attempting to validate the fields of the entity that is initiating the relation. So, in the case where someone is viewing an Organization record and is adding a connection to a Contact record, the form incorrectly validates the Organization record's data rather than the Contact's submitted values, even though the Organization record has not been changed.
gcb’s picture

Assigned: Unassigned » gcb

  • gcb committed 142c6e6 on 7.x-1.x
    Refactor relation form logic. Updates #2428227.
    
gcb’s picture

Assigned: gcb » Unassigned
Priority: Major » Minor
Status: Needs review » Needs work

Above patch did not resolve the issue for me. I have refactored this logic in commit 142c6e6. There is still some strangeness specifically with adding contacts when we have different types, but this is an improvement.

Remaining issue:

when creating a relation TO another contact, when you have multiple contact types, the form breaks down after using the contact-record-type selector more than once.

Downgrading to "minor".