I'm using a cck Location Field on different node types.
Setting the "additional Field" to required on the node settings has no effect on
the node creation form.
The field gets no asterix an can be empty.

I also noticed that changing a location setting on a field instance for a node type affects any
node type using this field (which may be working as designed).

Comments

ankur’s picture

Status: Active » Closed (works as designed)

This is by design for the most common use case. If you have a situation where the additional field is required, my suggestion would be to add some code in an implementation of hook_form_alter() that set's the #required value to TRUE in the form array.

samhassell’s picture

You can't use hook_form_alter() to do this as the location fields are not available in $form AFAICT. You can use hook_locationapi() though:

/**
 * Implements hook_locationapi().
 */
function mymodule_locationapi(&$obj, $op, $a3 = NULL, $a4 = NULL, $a5 = NULL) {
  switch($op) {
    // Make the additional field required.
    case 'field_expand':
      switch($a3) {
        case 'additional':
          return array(
            '#required' => TRUE,
          );  
          break;
      }   
    break;
  };  
}

I worked this out by looking at location_locationapi() in location.module. You can do a bunch of other cool stuff with this hook.