I need a selection list with one value, which is not the first value, preselected.

CommentFileSizeAuthor
#7 forms.module_0.patch3.55 KBaltano
#3 forms.module.patch3.43 KBaltano

Comments

altano’s picture

This isn't just a lack of support in the Forms project. form_select does not provide an option for default selection.

I'll look into it

altano’s picture

Assigned: Unassigned » altano

Er, I totally misread the api docs. Ignore the last post.

altano’s picture

StatusFileSize
new3.43 KB

Here's the patch

peterx’s picture

Excellent. 99% there. The code works except for one thing. I have a, *b, c. The * goes in to the key then is copied to the value. The * is detected and removed from the value but not the key. I quickly added an if() within the value code to remove * from the key. It works for *b.

The extra if() would not handle 1:a;*:*b;3:c where * is a valid key for value b.

altano’s picture

I'm not really following you. "a, *b, c" is not valid syntax?

peterx’s picture

That should be a;*b;c. Using your examples from the code, 1:red;2:blue;3:*green works. The problem is with red;blue;*green. The code $value = $key; copies *green from key to value. $value = substr($value, 1); then removes the * from the value but not the key.

I added something to remove * from the key to fix the problem for my current list. I then thought about the problem and considered the example 1:red;2:blue;*:*green where * might be a required value. I have had * as a value in selection lists.

altano’s picture

StatusFileSize
new3.55 KB

Sorry, Firefox wasn't refreshing the form for some reason so I didn't catch the bug. I guess I shouln't have tried so hard to keep the if/else block small :O

Here's another patch (restore to original first)

peterx’s picture

The patch is working on my site for a;*b;c. Thank you.

quicksketch’s picture

Status: Needs review » Closed (fixed)

Forms and survey modules are no longer being maintained, use Webform module instead.

---Closing down issue queue of survey module---