Community

D7 fields, How do I remove N/A from Radio Button list?

How do I remove N/A from Radio Button list?
I don't want the option required.
I have seen these two Documentation pages:
http://drupal.org/node/617694, and http://drupal.org/node/656622, but they pertain to CCK on D6.

Thanks

Comments

Try not making the field

Try not making the field mandatory

Mandatory Field

I didn't make the field mandatory. When you make it mandatory the n/a goes away, but I don't want the field mandatory.

Ditto

Has anyone got a solution for this? I also don't want to make the field mandatory.

The reasoning of why the n/a

The reasoning of why the n/a appears in this situation makes sense to me: "Removing the n/a option means a user cannot empty the field. 'no value' is a valid value for a non-required field." But I also get that it won't always make sense from a user's perspective.

It would be nice if you could change what N/A said, that you could make it the default, and that it would be selected again when you come back to edit it.

However, there is one non-coding workaround to at least address the language issue:

Make the field required, AND add your own version of the N/A that makes sense in context: unknown, undecided, decline to answer, etc... And make it the default value.

The downside to this is that this answer would appear in the content (unlike when N/A is selected).

_

The problem is there are perfectly valid use cases for actively forcing the user to make a selection that does not include any type of n/a. Providing a default means it could be that the user didn't even bother to read the question or actually select the submitted response.

I haven't had to do this for d7 yet, but in a pinch you could use a select list instead.

_
Don't be a Help Vampire - read and abide the forum guidelines.
If you find my assistance useful, please pay it forward to your fellow drupalers.

makes sense, except:

just an FYI, this might be an "edge case":
I'm adding a "gender" checkbox to my user profile and preselect it with male (90% male audience on my site...).
I don't want to make it a required field on registration, only on "edit" to fill out additional profile fields.
If I make the field required it will automatically be required on the user registration page.
I can hide the DIV for the "N/A" option with css.

It gets worse with the below

It gets worse with the below bug. If you make a radio field required, then you are screwed when submitting the form when no user selects it. So what, you say? If you use javascript/ajax/conditional fields module to create conditional forms, then you are S.O.L.
http://drupal.org/node/811542
Bug since 2010

Not Answered

Wouldn't the solution in this edge case be to check N/A by default and then hide it (either via css or in the form tpl.php) That way the default is "Not Answered" but both radio buttons can display as unchecked. I also think this wouldn't interfere with conditional fields.

A list of some of the Drupal sites I have designed and/or developed can be viewed at http://motioncity.com/drupal

Well if we're talking of wriitng modules ...

Well, yes, any Drupal problem can be solved with writing your module or altering the form or template. I think the issue is that the person wants to do this without having to write anything (non-coding).

This may help

Try using something like this

<?php
unset($vars['form']['group_if_in_fieldset']['field_the_radios']['value']['']);
?>

removing NA field

If you are working with Drupal 7 and using the Drupal interface; after adding all of your fields, save. go back into manage field and remove the NA choice by deleting it. done.

"The skill of coding is to create a context in which other people can contribute."

Use CSS

You can add a class definition of display:none, if you do not want it to be mandatory.
In this way you can mange it in both node create/edit form and also in node view.

Saurabh Dhariwal
Email:saurabhdhariwal.com@gmail.com
http://addwebsolution.com
Skype:add.websolution

Using PHP & CSS

A quick solution is to have Drupal add a form-disabled class to the N/A form-item by adding the following function to your template.php file.

<?php
function <theme_name>_form_element($variables) {
 
$element = $variables['element'];
 
// Disable radio button N/A
 
if ($element['#type'] == 'radio' && $element['#return_value'] === '_none') {
   
$variables['element']['#attributes']['disabled'] = TRUE;
  }
  return
theme_form_element($variables);
}
?>

Then you can use CSS to do

.form-radios .form-disabled {
  display: none;
}

You can remove using hook_form_alter

After adding bellowed single line's code on your hook_form_alter "N/A" removed from Radio Buttons.

<?php
unset($form['field_name']['und']['#options']['_none']);
?>

Thank you.

nobody click here