4

How can I delete the option -None- of the select list in a cck field. The field is not required.

3
  • Do you want to delete it and so there's no more "empty" option (which is what keithm suggested) or to you want to rename it ?
    – tostinni
    Aug 9, 2011 at 20:07
  • 2
    CCK will always provide the None option for a select field unless it is required.
    – keithm
    Aug 9, 2011 at 21:27
  • I need to delete the option "none" of the select list in a cck field with select list.
    – cabita
    Oct 17, 2011 at 17:46

2 Answers 2

2

I have created a module and used form_alter hook to remove the None value of a CCK select list:

<?php

function MODULENAME_form_alter($form, &$form_state) {
    //dsm($form['form_id']['#id']); //dsm() used for see the ID of form
    if ($form['form_id']['#id'] == 'edit-test-content-type-node-form') {
      $form['#after_build'][] = 'change_form_values_after_build'; //call to a function
    }
}

function change_form_values_after_build($form, &$form_state) {
  $new_array = array();
  $new_array = array('Yes' => 'Yes','No' => 'No');
  $form['field_test_select_list']['value']['#options'] = $new_array;
  return $form;
}

In this case, I have used the function change_form_values_after_build (introduced by #after_build) to introduce the desired values in an array, but I guess that you can make a database query, to retrieve the options that you have added in the interface of field, and remove the undesired value, to return again to the form the array with correct values.

I hope information be useful.

1
  • It's a good alternative, it works for me. Thanks very much.
    – cabita
    Oct 18, 2011 at 3:16
2

Make the field required in Global Settings.

2
  • This is correct. If the field is not required, the list of values for a select field should contain a value that is selected when the user doesn't want to enter any value.
    – apaderno
    Aug 9, 2011 at 23:32
  • The field IS NOT REQUIRED. I need to delete or change the option -None- by 'Please choose'. If the field is not required, i need that the value selected by the user when the user doesn't want to enter any value be "Please choose".
    – cabita
    Aug 9, 2011 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.