I have a site which is using the Distance/Proximity filter, which is exposed so that users can search for retailers near an address they provide. The result is a map and attached table that shows nearby retailers sorted by distance. So far, perfect.
However, I've noticed that the user can choose a taxonomy term (e.g. Distributor), a Country, and leave the Postal Code field empty. When this happens, all results matching that taxonomy term are displayed, not just those within the Country.
I have attempted to hook the postal_code field using hook_fork_alter in my theme to make it a required field, with no luck (my lack of PHP/Drupal foo, I'm afraid). However, adding #required to the postal_code form element in location_views_handler_filter_proximity.inc does the trick, in the sense that now the user has to enter an address as well.
So, I guess I'm asking for help with one of several things:
- Some code for template.php or a custom module that will alter the Postal Code field to make it required
- The option within the module to choose if it should be required (when configuring the exposed filter)
- Change the module behaviour so the Country field will be respected when considering other exposed filters in the view.
Thanks.
Comments
Comment #2
millionleaves commentedFurther note ... if I change the postal_code field to #required => 'True', then the Views page with the exposed filter on it displays the field required message, "City/State or Postcode field is required."
I tried setting the default Postal Code in the filter settings, and also the Require input before results are shown option in Better Exposed Filter, with no luck. Even just loading the page generates the form validation error. In the end, I simply disabled the #required setting for the postal_code field, so I'm back to square one....
Any help would be appreciated.
Comment #3
millionleaves commentedComment #4
millionleaves commentedI've just created a new issue in relation to point 3 above: Ensure that the filter works correctly if a country is selected but no City/State/Postal Code value is supplied:
https://www.drupal.org/node/2826474
I don't think this issue is superseded by the new issue, since there may still be a use case to require a Postal Code value in the Distance/Proximity exposed filter. However, in creating the other issue, I found some comments in the module from @merlinofchaos that helped me understand why the form behaves as it does if you make the postal code a required field.