Closed (fixed)
Project:
Webform
Version:
7.x-4.x-dev
Component:
User interface
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
14 Aug 2013 at 08:02 UTC
Updated:
5 May 2014 at 02:50 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
quicksketchI actually think this is possible... but only in the 4.x branch because it has full token support. To do this, set up a select list with the two options:
I think that would display the first field value as the label of the first choice and the second field value as the second choice, but I'm not 100% sure you can do that, accessing individual delta values. You definitely could do it if the two date fields were separate. Unfortunately this definitely won't work in the 3.x branch. The only option there is to use hook_form_alter() to inject the choices, but that generally won't have an effect on the sent e-mails, viewing submissions, etc. so it's not a real good option.
Comment #2
knalstaaf commentedI'm now trying it on a local 7.x-4.x-dev installation and the Date field tokens are indeed available. I can't get it to work though (used tokens, tried the ones you proposed as well). Both the options are available for the visitor but they seem to have no label (I'm just seeing 2 radio buttons).
Comment #3
quicksketchHi @knalstaaf, thanks for trying out the new version. So I think this *should* work, but after looking at the code I can tell why it's not. The _webform_select_options_from_text() function is where token-replacement happens, but it doesn't have access to the $node object, which is necessary to replace the field tokens.
To fix this problem, I think we should separate the token replacement from the _webform_select_options_from_text() function, and run webform_token_replace() on each of the labels. I'm moving this to a bug, since at least we shouldn't be saying you can use node tokens in the dialog browser if it's not really available.
Comment #4
thechanceg commentedHere is my go at a patch for this.
I just did what you suggested quicksketch. Moved webform_replace_tokens from _webform_select_options_from_text() to _webform_render_select().
Comment #5
thechanceg commentedComment #6
quicksketchThanks @thechanceg! This looks great, exactly what I had in mind.
The only problem here is that we should wrap the token replacement here:
There should be an
if ($filter) { }check around that. I know the $filter parameter isn't well-understood, but it's used when we want to display the element or results with the raw tokens in place instead of being replaced (e.g. in form builder or on a settings page).Comment #7
thechanceg commentedThanks for the clarification @quicksketch. I can see how that would be necessary.
Here is a revised patch. Now with 100% fewer spelling errors in the description!
Comment #8
jweowu commentedThe patch works for me. The code looks sane, and has quicksketch's prior approval for the approach, so I think RTBC.
Comment #9
quicksketchThis patch still needed work because it didn't take into account any of the following:
- Because the $filter option is no longer used in several functions, it should be removed from the argument list.
- Because $filter isn't used in option callbacks any more, it should be removed from the webform.api.php documentation as well.
- The patch only affected node tokens when rendering the form, but not in table, analysis, or csv downloads.
- We didn't take into account Grid components which use the same callbacks for generating options lists.
I *think* this version addresses all these problems, but we should confirm that node token replacement is working in all the places we expect:
- Rendering the form.
- Rendering results and e-mails.
- Analysis, table, and CSV downloads.
- And all of the above for grid components in addition to select components.
Comment #10
jweowu commentedThere's at least one problem with this patch: It removes the
$filterargument from_webform_select_options_callback(), but that function still tries to use it:return $function($component, $flat, $filter, $arguments);That function variable comes from
$info[$name]['options callback'], and grepping for 'options callback' gives the following:Each of those functions takes a
$filterargument, but none of them uses it in any way.Comment #11
quicksketchThanks @jweowu for the feedback! You're right on all counts. I've rerolled to fix these issues. Great catches.
Comment #12
quicksketchFinally pushed this into the 7.x-4.x branch. Thanks everyone here for their work on this one.
Comment #13
knalstaaf commentedCool, thanks!
Throughout my five year stay on the Drupal community it occurred to me that you're one of the most dedicated maintainers. I'm convinced most of the maintainers are as dedicated as their schedule allows them to, but yours is rather exceptional, as well as in general feedback on issues and support as in developing, innovating and perfectioning modules.
It doesn't go unnoticed. Thanks for all the effort so far!
Comment #15
sunshinee commentedLeaving this as fixed, but want to add a note in case it will help others.
If you are using the Values module to provide select option lists, this update breaks the functionality and returns an error "Missing argument 4 for values_webform_webform_select_options()."
There is an issue filed in the Values issue queue: https://drupal.org/node/2242571
Joy
Comment #16
fenstratNeeds porting to 8.x-4.x.
Comment #17
fenstratCommitted and pushed 0838ce1 to 8.x-4.x. Thanks!