Avoid duplicate ID for a field that appears multiple times on the same form I'm having a problem with duplicate ID's for a custom field widget.

The scenario:
I have an order form, that contains 2 field collections "pick-up" &amp; "delivery".
Both these collections contain the same field "field_delivery_profile" which is a customer profile reference field with a custom field widget.
In the hook_field_widget_form regardless of whether I assign the element an id or not, the ID is the same for both occurrences of the field in the form.

One thing is the breaking W3C standard but the most crucial one for me right now, is that I need to check both fields value change through JS and have to be able at least predict the IDs. Is there maybe a way to get the parent field-collection (that's containing the field) information for assigning a better id?

Best,

Alari
Drupal has a helper function for that:

drupal_html_id():


  Prepares a string for use as a valid HTML ID and guarantees uniqueness.