After upgrading from 2.9 to 3.1 I noticed that the first item of the select list is always selected, no matter what option I select in my user profile.

CommentFileSizeAuthor
#3 webform_filter_empty.patch532 bytesquicksketch

Comments

tomsm’s picture

Priority: Normal » Major

I think this has a major priority.

I will try the explain the issue better:

My user profile contains select lists.
These fields also appear in my webform and are automatically filled in with tokens %profile[key].

When a registered user fills in the webform the default value for these select lists is always the first option of the profile select list.

As a workaround I tried deleting the default value of the webform component (deleting %profile[key]) so that "Select..." would appear notifying the user that this field should be verified.
But still the first option appears.

Anonymous users do see "Select..." as it should be.

Info: I use Token 6.x-1.14

Maybe duplicate issue of http://drupal.org/node/853836#comment-3337526 ?

PS: I also tested with 6.x-3.0-beta6. The issue already existed then.

quicksketch’s picture

Title: %profile[key] token for select list does not work » First item of select lists selected as default if it has a key of "0" when no default is set

Updating title to reflect actual problem. Please keep other issues that are somewhat related closed/fixed, it's hard to track a problem if it's reported in 3 different places.

quicksketch’s picture

Status: Active » Needs review
StatusFileSize
new532 bytes

I think this patch corrects the problem. A default value of "" (an empty string), was getting returned as NULL by our filtering function. As far as I could tell, this problem didn't really have anything to do with using %profile tokens, though I tested it with or without them and both seem to work fine after this patch.

tomsm’s picture

I applied the patch: The problem is partially solved.

FIXED: When I leave the default value of the component empty, the default value in the webform is "Select...".

NOT FIXED: When I set as default value %profile[profile_title], the first option is always selected as default.
My profile select list "title" has the following options: Mr., Mrs., Ms., Dr.
When I select in my user profile another option, for example "Dr.", Webform always takes the first value in the list, namely "Mr.".

My options are:
0|Mr.
1|Mrs.
2|Ms.
3|Dr.

Validation: Mandatory
Display: listbox

I also tried as options:
1|Mr.
2|Mrs.
3|Ms.
4|Dr.

The same happens with the other select list I have in my user's profile.

Maybe this problem should become a new issue?

quicksketch’s picture

NOT FIXED: When I set as default value %profile[profile_title], the first option is always selected as default.
My profile select list "title" has the following options: Mr., Mrs., Ms., Dr.
When I select in my user profile another option, for example "Dr.", Webform always takes the first value in the list, namely "Mr.".

The default value of a select list will use the "key", not the "value" part. So if you want to use %profile['profile_title'] as the default, you have to make key|value pairs like this:

Mr.|Mr.
Mrs.|Mrs.
Ms.|Ms.
Dr.|Dr.

Thanks for trying out the patch, I'm glad to have another edge-case fixed dealing with 0's and select lists. Let me know if this approach of new keys works for you.

tomsm’s picture

@ quicksketch

Yes, the new approach works! Thanks!

quicksketch’s picture

Status: Needs review » Fixed

Super, I've committed this patch and it will be in the next version of Webform. I expect that we should put out a new release later this week or next after additional users have upgraded. Thanks!

akalata’s picture

Patch worked for me as well. Thanks!

ludo.r’s picture

Status: Fixed » Active

I have a similar issue with version 3.1

The component :
Type : select
Default value : empty
Options :
0|No
1|Yes
Mandatory : yes
Listbox : yes

Option "No" is already selected and there is no "Select..."

quicksketch’s picture

Status: Active » Fixed

This problem is in the 3.1 version (as noted in the "version" property in the original report). It has been fixed and will be included in 3.2.

ludo.r’s picture

Oh sorry, i didnt get that!

Thanks!

roball’s picture

Title: First item of select lists selected as default if it has a key of "0" when no default is set » First item of select lists selected as default if no default is set

Can confirm this issue with 3.1. It occurs always when no default has been set, regardless of key values (for example, if you use the module-provided list of all countries, Afghanistan is always preselected as default).

Can also confirm that the patch of #3 solves the problem :-) Thanks!

Status: Fixed » Closed (fixed)

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

roball’s picture

Thanks for the fix which is now in 3.2. Working fine.