I have tried
0|Choose
|Choose
but nothing works please explain, how to force user to choose one value.
I have tried also to leave default value empty.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vernond’s picture

Are you trying to make the dropdown list say "Choose" instead of "Select" or "None"?

webankit’s picture

No I don't see any such option called select or none,
how to get such an option?

Is is that select or other module creating some problem?

vernond’s picture

I am not understanding your issue. Please explain exactly what you want to do.

webankit’s picture

I just created a select list:-
with options:
a|A
b|B
c|C
Also i am using a select or other module so last option is "Other"

I have made this mandatory. I want to force user to choose value.
But on viewing form, the first value become its default value, so i can't use this mandatory option.
How to add this "Select or None" option?

webankit’s picture

Project: Webform » Select (or other)
Version: 7.x-3.9 » 7.x-2.5
Component: Documentation » Webform
Category: support » bug
Priority: Minor » Major

I got it select or other creates this problem so moving the issue.

danielb’s picture

What's the problem?

That it automatically selects the first option when you make it mandatory?

That sounds normal to me.

webankit’s picture

FileSize
17.69 KB
15.9 KB

The problem is:-
When i don't use select or other & make a field mandatory , there is an option select on top, so people are forced to make a choice.
But when i use select or other the "Select" option disappears.

danielb’s picture

I based the behaviour of this on CCK select lists at the time this module was created. That must have changed at some point?
I guess I'll change it too.

danielb’s picture

Status: Active » Fixed

Fixed as a result of fixing this: #1205532: make other field optional

danielb’s picture

Nope, it was the other way around.

webankit’s picture

Version: 7.x-2.5 » 7.x-2.6
Status: Fixed » Active

Still same

danielb’s picture

Status: Active » Closed (fixed)

I've definitely added it
http://drupalcode.org/project/select_or_other.git/commitdiff/ec6625d8d59...

I've tried to follow the logic of options.module's select lists. It works for me and everything.

It is possible that you won't notice the behaviour on existing fields, indeed a field with a value in it will no longer show the 'please select' option, and that is the way the options.module appears to work too. I can't make any further assessment from a two word response. I don't know what you tried, and I can't really take any more action without a thorough analysis or explanation as to why what I did is incorrect.

dawansv’s picture

Title: mandatory value in select list » "- Select -" or "- None -" does not appear in select list
Version: 7.x-2.6 » 7.x-2.x-dev

As far as I can tell this is still a problem. The "- Select -" (when field is required) or "- None -" (when field is not required) does not appear at the top of the list.

I traced the problem back to the core include/form.inc.

Function form_process_select($element) bases its decision on whether to display these value on whether $element['#empty_value'] is set (among other possibilities).

Problem is that select_or_other does not pass that value along in function select_or_other_element_process

After I added '#empty_value' => $element['#empty_value'], to the list of elements that are passed along, all is back to normal and the "- Select -" or "- None -" is back.

 // Create the main select box
  // Note that #title, #default_value, #disabled, #multiple, #options, #attributes,
  // #required, #size and #empty_value as passed to the select box from the main element.

  $element['select'] = array(
    '#type' => $element['#select_type'],
    '#title' => $element['#title'],
    '#default_value' => $element['#default_value'],
    '#disabled' => $element['#disabled'],
    '#multiple' => $element['#multiple'],
    '#required' => $element['#required'],
    '#size' => $element['#size'],
    '#empty_value' => $element['#empty_value'],
    '#options' => $element['#options'],
    '#attributes' => $element['#attributes'],
    '#weight' => 10,
  );

Now I have to figure what #empty_value really does, because the above declaration will declare it even if it is not present I suppose...

dawansv’s picture

Ok, so instead of just adding it to the list, I think adding it only if it is set is the correct way...

  if (isset($element['#empty_value'])) {
    $element['select']['#empty_value'] = $element['#empty_value'];
  };
perisdr’s picture

@dawansv where do you add the code? Line 117?

Liam Morland’s picture

Priority: Major » Normal
Status: Closed (fixed) » Needs review
FileSize
723 bytes

This issue still exists. Patch for same approach as #14 attached.

Liam Morland’s picture

danielb’s picture

Status: Needs review » Fixed

thanks, wasn't aware of such a property

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

  • Commit ec6625d on 7.x-2.x, 7.x-3.x, 8.x-3.x by danielb:
    Issue #1315754 by danielb: Please select option.
    
    
  • Commit e4a94b9 on 7.x-2.x, 7.x-3.x, 8.x-3.x by danielb:
    Issue #1315754 by danielb: Please select option.
    
    
  • Commit 906aa5b on 7.x-2.x, 7.x-3.x, 8.x-3.x by danielb:
    Issue #1315754 by Liam Morland, dawansv: Empty value property.
    
    
rimu’s picture

This problem is back, in D7.59. It looks like the #empty_value attribute is only used for required fields so optional fields end up with no '- None -' in them.

FYI my work-around is to use hook_form_alter to add a '- None -' to the #options array. e.g.

//add "None" as an option on select_or_other fields
  foreach($form as $k => $v) {
    if(is_array($form[$k])) {
      if(!empty($form[$k]['und']['#type']) &&
         $form[$k]['und']['#type'] == 'select_or_other' &&
         empty($form[$k]['und']['#required'])) {
        $form[$k]['und']['#options'] = ['_none' => '- None -'] + $form[$k]['und']['#options'];
      }
    }
  }