-1

We're using the Address module to provide address functionality.

But its widget is in a container ( details form element) enter image description here

But what we need instead that is to divide the elements, something like in the following image where fields are lined horizontally.

enter image description here

My question is How we can ungroup the address field elements ?

Dump of field_address widget on form_alter follows

ksm($form['field_address']['widget'][0]);

I did similar task with 'author' group but address fields structure is a little dfferent. if you look at the dump of address field you will see the PostalCode, State and Suburb does not exist :

array(11)
'#title' => string(7) "Address"
'#title_display' => string(6) "before"
'#description' => string(0) ""
'#field_parents' => array(0)
'#required' => boolFALSE
'#delta' => integer0
'#weight' => integer0
'#type' => string(7) "details"
'#collapsible' => boolTRUE
'#open' => boolTRUE
→'address' => array(5)
'#type' => string(7) "address"
→'#default_value' => array(13)
'country_code' => string(2) "AU"
'administrative_area' => string(0) ""
'locality' => string(0) ""
'dependent_locality' => string(0) ""
'postal_code' => string(0) ""
'sorting_code' => string(0) ""
'address_line1' => string(0) ""
'address_line2' => string(0) ""
'organization' => string(0) ""
'given_name' => string(0) ""
'additional_name' => string(0) ""
'family_name' => string(0) ""
'langcode' => NULL
'#required' => boolFALSE
→'#available_countries' => array(1)
'AU' => string(2) "AU"
→'#field_overrides' => array(8)
'givenName' => string(6) "hidden"
'additionalName' => string(6) "hidden"
'familyName' => string(6) "hidden"
'organization' => string(6) "hidden"
'addressLine1' => string(6) "hidden"
'addressLine2' => string(6) "hidden"
'sortingCode' => string(6) "hidden"
'dependentLocality' => string(6) "hidden"

enter image description here

  • You could add custom fields for that, hide the address fields and then add a custom submit handler which saves the custom field values into the address fields. And have you already tried to override the widget via hook_form_alter? – leymannx Mar 19 at 14:03
  • hi @leymannx. thank you for the suggestion. actually it doable but I'm looking for a cleaner way. a way to easily customize the address wrapper. additionally, the address has good validation to validate the zipcode based on Area. do you have any suggestion to customize it's template? – Yusef Mohamadi Mar 19 at 15:43
  • @leymannx I've update question with dump of address field widget – Yusef Mohamadi Mar 19 at 17:01

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.