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.
When you try to add a fourth poll choice the new fields replace the fields for the 3rd choice, so you can never get more than 3.
Comment | File | Size | Author |
---|---|---|---|
#7 | pollfield.module.patch | 3.35 KB | mr.j |
Comments
Comment #1
mr.j CreditAttribution: mr.j commentedI should add that I had 2 choices by default.
I increased the default number to 5 or 6 and that works in allowing me to make 5 or 6 choices, but it is not possible to add more by clicking the add choice button.
Comment #2
bryan kennedy CreditAttribution: bryan kennedy commentedInteresting. I can confirm this bug. How to replicate:
I'll take a look at this and see if I can figure out what's going on. Obviously this is probably linked to all the default option issues, but I'm glad you brought up this specific problem.
Comment #3
hsimeoni CreditAttribution: hsimeoni commentedsame here
I think it is critical for someone using it.
It is a critical functionality
Comment #4
bryan kennedy CreditAttribution: bryan kennedy commentedI agree it is critical, but I set the version back to dev. This issue presents itself in the latest dev code, and I am focusing on fixing it there. These won't be any work done on 6.x-1.9-beta1.
I haven't abandoned this issue, just have gotten pretty swamped on the weekends lately. I spent a bit of time working on it this week, and I'll update more in a few days.
Hsimeoni, you assigned this issue to yourself. Are you planning on doing some work on this code? I'd welcome any patch submission, but just wanted to check. Cheers.
Comment #5
jordan8037310 CreditAttribution: jordan8037310 commentedHas any more work been done on this issue? Experiencing the same problem.
Comment #6
lemartialou CreditAttribution: lemartialou commentedHi there,
I was experiencing the same problem too (which seems to be a duplicate of this one: https://drupal.org/node/1168408)
So yesterday I decided to take care of myself by diving into tho code... for the win!!! Yaaay! ;p
I'm not a pro drupal/php developer, so maybe I'm doing something wrong, but I tested my solution as much as I could, and it really seems to work as it should.
Also I'm not a patch maker (sorry for that) so I'll just tell you what I did, taking the last 6.x-1.x-dev as a reference.
So, in the file pollfield.module
On line 1051, replace:
$count_choices = max($count_default_response_fields, intval(count($node_choices)));
by:
Reason: the variable $node_choices (in fact it's the variable $element['#value']['choice']) doesn't seem to return anything when rebuilding the form after an add_choice action, looking at the 6.x-1.13-beta1 code (which kind of worked) under some condition it used $element['#value']['group'] to do the counting, this worked, but only for the form generated by the add_choice action, so not when $noide_choices is available.
Then, around line 1070:
I simply removed this part, it doesn't seem necessary to me and can lead to problems. We don't need to check if the first choice is empty, the module already check if the last choice is empty to prevent adding more choices, we don't care about the first choice don't we? (well unless there is only one choice maybe, I've not tested this possibility ;p)
With this $first_choice checking, if a user has a poll full of questions, and then for some reason he decides to remove only the first one and leave the others, on his next node edit all the other choices would disappear, with no way to get them back, he only get the first blank choice, and has to override everything.
Then around line 1076:
if (drupal_strlen($value_choice) > 0 || $delta << $count_choices || $first_empty) {
Replace by:
if (drupal_strlen($value_choice) > 0 || $delta < $count_default_response_fields) {
Reason: No need for $first_empty, I think the << is a mistype, and here we want to test if the maximum delta is below the default number of choices, so that when the add_choice form rebuilding takes place it doesn't remove empty choices that should be present.
And finally, around line 1102:
Here there are 6 occurences of the variable $number, which doesn't seem to be cited anywhere else, and is not initialized.
Again, looking at the 6.x-1.13-beta1 code I realized that it was a vestige. The $number variable has been replaced by the $i variable in 6.x-dev code (used just above this code).
So just replace those 6 $numbers by 6 $i and everything should be good.
Et voilà! It's all it takes to get the "add choice" button back to work, at least on my site ;)
I hope this will work for you too, don't hesitate to tell me if I'm doing something wrong, and if I'm not I hope there will be some "patchers" around to take care of this problem ;)
Cheers!
Comment #7
mr.j CreditAttribution: mr.j commentedPatch attached. It includes your fixes and also one more to make the pollfield fieldset expanded if it has a question set. i.e. when editing the node it always annoyed me that you had to expand the pollfield fieldset when it had been used.
The patch does solve the problem of adding new poll choices.
However I have noticed a serious bug that seems to be common to AHAH implementations on Drupal 6, as described here:
http://jbenner.net/blog/prevent-ahah-the-right-way-from-breaking-with-va...
1. Create or edit an existing node with a pollfield. Leave a required field such as the title or body blank.
2. Fill in all poll choices, and make sure you add some extra choices.
3. Save the node.
4. The page refreshes and you are told to fill in the required fields that you left blank in step 1. Fill in the required fields and save again.
5. The form is submitted to the wrong URL and you will get a white page with what looks like the AHAH response from the last "more choice" request instead of seeing the published node.
This is a common problem because users often leave the body field empty when creating a poll and put everything in the poll question field instead.
The solutions posted in the linked article do not work due I think to this being a CCK-based module. I tried for a few hours and couldn't work it out. This module appears to be abandoned and the readability of its code is terrible so I don't expect that much work will be put into solving this.
Comment #8
lemartialou CreditAttribution: lemartialou commentedThank you for making the patch! ^^
To make the fieldset automatically expanded I've found another solution that doesn't rely on the question field, take a look at https://drupal.org/node/2044663 (I tried to resolve some other problems there too)
Now this AHAH problem looks like a pain in the...
Comment #9
mr.j CreditAttribution: mr.j commentedA lot of trouble could be saved by just entering poll choices using a single text area with each choice added on a new line, like Drupal does with the block configuration pages. It would take up far less space and less code, there is no AHAH required, and no associated issues.