Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#16 | select_or_other_none_value.patch | 723 bytes | Liam Morland |
#7 | Picture 7.png | 15.9 KB | webankit |
#7 | Picture 8.png | 17.69 KB | webankit |
Comments
Comment #1
vernond CreditAttribution: vernond commentedAre you trying to make the dropdown list say "Choose" instead of "Select" or "None"?
Comment #2
webankit CreditAttribution: webankit commentedNo 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?
Comment #3
vernond CreditAttribution: vernond commentedI am not understanding your issue. Please explain exactly what you want to do.
Comment #4
webankit CreditAttribution: webankit commentedI 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?
Comment #5
webankit CreditAttribution: webankit commentedI got it select or other creates this problem so moving the issue.
Comment #6
danielb CreditAttribution: danielb commentedWhat's the problem?
That it automatically selects the first option when you make it mandatory?
That sounds normal to me.
Comment #7
webankit CreditAttribution: webankit commentedThe 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.
Comment #8
danielb CreditAttribution: danielb commentedI 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.
Comment #9
danielb CreditAttribution: danielb commentedFixed as a result of fixing this: #1205532: make other field optional
Comment #10
danielb CreditAttribution: danielb commentedNope, it was the other way around.
Comment #11
webankit CreditAttribution: webankit commentedStill same
Comment #12
danielb CreditAttribution: danielb commentedI'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.
Comment #13
dawansv CreditAttribution: dawansv commentedAs 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.
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...
Comment #14
dawansv CreditAttribution: dawansv commentedOk, so instead of just adding it to the list, I think adding it only if it is set is the correct way...
Comment #15
perisdr CreditAttribution: perisdr commented@dawansv where do you add the code? Line 117?
Comment #16
Liam MorlandThis issue still exists. Patch for same approach as #14 attached.
Comment #17
Liam Morland#1490208: #empty_value not copied into select element marked as duplicate of this.
Comment #18
danielb CreditAttribution: danielb commentedthanks, wasn't aware of such a property
Comment #21
rimu CreditAttribution: rimu commentedThis 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.