Changing value of min / max resolution for an image field dynamically based on a previous select list Does anyone know if there is a way in Drupal 7 to change dynamically the value of minimum / maximum resolution for an image base on a previous select list.

Example :

I have a select with 3 elements :


Square
Portrait
Landscape


When I select Square, the min / max resolution would be set to 200x200, if Portrait 200x400 and landscape 400x200.

I could create 3 different image field but in the future I'll have more type of layouts and I'd rather have only one image field (for database and theming purpose)

I was thinking State API but no solution there.
I came up with a good solution using #ajax property from the Form API :

I declare hook_form_alter and add the #ajax on my push type select field.

/**
 * hook_form_alter
 */
function my_module_form_node_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'push_node_form') {
    // Add id to field image for ajax reload
    $form['field_push_image']['#prefix'] = '&lt;div id="image-field-to-reload"&gt;';
    $form['field_push_image']['#suffix'] = '&lt;/div&gt;';
    // Create ajax reload function
    $form['field_push_type'][LANGUAGE_NONE]['#ajax'] = array(
      'callback' =&gt; 'reload_image_field_resolution',
      'wrapper' =&gt; 'image-field-to-reload',
      'method' =&gt; 'replace',
      'effect' =&gt; 'fade',
    );
  }
}


Then in the field settings I put a resolution as a key from the select list like this :

200x200|Square

200x400|Portrait

400x200|Landscape

And then I reload the image field with the proper resolution base on the select value key.

/**
 * Ajax callback to reload the image field
 */
function reload_image_field_resolution($form, $form_state) {
  // Get the value of the push type
  $type_value = $form['field_push_type'][LANGUAGE_NONE]['#value'];
  // Explode the value to make sure that it's a good safe key value representing
  // a resolution like this : 100x100
  $resolution = explode('x', $type_value);

  if (count($resolution) == 2 &amp;&amp; is_numeric($resolution[0]) &amp;&amp; is_numeric($resolution[1])) {
    // If the value is good, build a new array containing the new resolution
    $min_max_resolution = array(
      $type_value,
      $type_value
    );
    // Reset the max and min with of the image field
    $form['field_push_image'][LANGUAGE_NONE][0]['#upload_validators']['file_validate_image_resolution'] = $min_max_resolution;
    // Set the variable to pass to the theme function with empty description otherwise
    // the old string (with the basic resolution) will be concatenated to the new string.
    $variables = array(
      'description' =&gt; '',
      'upload_validators' =&gt; $form['field_push_image'][LANGUAGE_NONE][0]['#upload_validators']
    );
    // Return the approriate altered string using theme_file_upload_help()
    $form['field_push_image'][LANGUAGE_NONE][0]['#description'] = theme_file_upload_help($variables);
  }

  // Return the image field with its new resolution
  return $form['field_push_image'];
}