0

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" & "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

  • Use drupal_html_id, that will guarantee uniqueness – Clive Mar 3 '16 at 10:33
0

Drupal has a helper function for that:

drupal_html_id():

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

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.