4

I'm using Address Field module

I want to make it a required field but only the Country and City values. I want to leave the zip code and Address as optional. I don't find a way to configure it like this. Is it possible?

To provide more info, I am using Geocoder to fill a Geofield field. I want it to be able to geolocate with City and Country if only that are provided if also zip code and address are provided use them too.

EDIT: I forgot to mention that if I make the whole Address field non-required works as I want to, but I would like to make Country and City required, another way to look at the problem.

  • 1
    Check out this issue: Configurable non-empty value conditions. Posted on August 29, 2011 and still not even assigned to anyone. Good luck with getting an answer here... – Mołot Dec 4 '13 at 8:59
  • @Mołot yeah it looks like its been a problem for some years now...I think I will let it be for now and work in other issues and go back in the refining stage of the site. Thanks again for your help! – garcianavalon Dec 4 '13 at 14:47
  • I was helping you with it before you knew you need it :P reviewing patches since 2012. Sorry for a bitter tone of my first comment, but as you may tell, I'm tired with it. – Mołot Dec 4 '13 at 14:49
  • The fact that it still hasn't reached a working consensus (there are many intermediate patches) shows there's still work to be done. I'm slowly working my way through these issues, but ultimately there were bigger issues to tackle first. Also, form altering will work just fine even without a configuration for it. – Ryan Szrama Dec 5 '13 at 15:06
  • @RyanSzrama Thanks for your work. It is not an urgent matter so I can get along with letting all fields as optional. Is there anyway to keep up to date with the development of the module? – garcianavalon Dec 9 '13 at 12:30
1

I would use form_alter to hook into the form, identify the form element and unset or make required FALSE

eg:

mymodule_form_alter(&$form, &$form_state, $form_id){

  if($form_id == 'xyz'){
   $form['zipcode']['#required'] = FALSE;
   $form['address']['#required'] = FALSE;
  }

}

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.