2

I would like the user to choose the category when he creates a new node content. However, instead of radio buttons or dropdown list I would like to have selectable images, with exactly the same logic. Is it possible to somehow ovveride radio buttons / dropdown lists with options being displayed as images? So, for example instead of a radio button with 'Cars' label I would like to have a picture of a car, then for the next category another picture, etc. Any advice appreciated.

3

You can accomplish this with a combination of a little JQuery and CSS.

Here's some starting points

Then use a custom module to load the JS when needed using drupal_add_js() typically instantiated with a hook_form_alter().

Something like this:

/**
* Add example.js to content type 'car' create/edit form for example.module
*/
function example_form_alter(&$form, $form_state, $form_id) {
if ('car_node_form' == $form_id) {
  drupal_add_js(drupal_get_path('module', 'example').'example.js');
}

You can find more examples for detecting different forms and patterns on the hook snippets page.

  • Links are not anymore available. – user46175 Nov 4 '15 at 6:33
  • Looks like there are better solutions available today using css3. See this answer stackoverflow.com/questions/25345886/styling-radio-inputs?lq=1 which uses image replacement via the label element. Of course if you need the label element jquery could be used to replace the checkboxes with images. – Brent Nov 20 '15 at 23:18

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.