Hi,
We have created a view to show results from Webform submission data. This required a relationship on Webform submission data: Data field which works ok and the submission data fields are able to be pulled into the view.
One of the fields returns a date (deployment date). This date needs to be used as a filter e.g. show all rows from deployment date to today.
However the filter operator only offers text based/numeric options - greater than/contains etc. Date Views is enabled and works fine for views with content data but webform submission data doesnt seem to be able to be used as date objects?
How can Views that use webform submission data filter on dates?
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | webform-views-exposed-data-filter-2527608-13.patch | 7.85 KB | nmillin |
Comments
Comment #1
danchadwick commentedSupport requests are never more than Normal priority, as per the issue queue handbook.
You are correct. The data is always stored as a string, but webform's views integration supports both numeric and string data formats. Dates would be quite a bit more complicated because it would require converting the strings to dates (which isn't easy, particularly with the variations in day/month/year order, etc).
It would be possible for you to write your own views handler and add your own date component validation handler to ensure proper dates. Or you could write a generally-useful patch and post it here for incorporation into webform itself. I support the idea, but certainly don't plan to tackle this myself.
And by "you" I mean you personally, or someone you hire. I understand not everyone is a developer.
Comment #3
nmillin commentedI had a similar issue so I took a stab at creating this feature.
**Note** The Views Filter requires a Relationship to the Webform submissions: Data.
The patch includes:
This patch needs some TLC, but hopefully it can get the ball rolling. Let me know what you think.
Comment #5
nmillin commented*facepalm* Let's try that again with the patch having the right paths.
Comment #6
nmillin commentedComment #8
nmillin commentedOk... So apparently I'm having trouble creating a patch file because it includes a new file? I've read https://www.drupal.org/node/1054616 and can't wrap my head around this. I'm going to set the status to needs review and back away from this. Hopefully someone can help with my patch because my head hurts from banging against my desk so much.
Comment #9
alsantos123Thanks!
Comment #10
liam morland@#8 Use
git addto add all the changes you need to make, including the new files. Then make the patch withgit diff --cached. Let me know if you need more help with this.Comment #11
nmillin commentedHmmm... looks like trailing whitespace was the issue with my previous patch being failed. Trying again.
Comment #13
nmillin commentedOk, now the patch is corrupt. Trying with a new line at the end of the patch file.
Comment #14
nmillin commentedComment #15
liam morlandYou shouldn't have to edit the patch file. The results of the
git diffshould be exactly what you need.Comment #16
nmillin commentedHazaaa! Finally after getting the paths right, no whitespace, and adding an extra line at the end of the patch it passes!
@Liam I probably have something funky with my local setup because that is what I was doing. Something I'll need to look into.
Now this patch can be reviewed by others. Thanks.
Comment #17
mnovoa commentedHi
I try to apply this patch, but hi have errors..
There is another solution to filter by the date of a webform field?
thanks
Comment #18
nmillin commented@mnovoa make sure you apply the patch to the dev version (7.x-4.x) of the module. I just tried to apply the patch (instructions https://www.drupal.org/node/7404/git-instructions/7.x-4.x/nonmaintainer) and it applied cleanly.
Good luck!
Comment #19
Harsikesa commented@nmillin just wanna say thankyou very much for the patch, just started searching around for solutions, and just arrived here. The patch is working perfectly, but one thing that I don't know is how I can add a jQuery date picker into the exposed date filter?
Comment #20
nmillin commentedThe patch from #13 adds the jQuery datepicker that comes with Drupal core to the first data_date exposed filter via a webform_form_views_exposed_form_alter & a webform_views_query_alter.
The patch would need to be tweaked if there could be multiple exposed date filters. Doable, but I would want to see if the module maintainers are interested in this functionality, if a separate module is better for this, or if there is another way for doing this.
Comment #21
liam morlandThis looks like it could be useful. I would like to see some tests.
Comment #22
nmillin commentedSure... I used $data['webform_submitted_data']['data'] as a starting point to build this functionality. It looks like there aren't any tests for $data['webform_submitted_data']['data'] that I can use as a starting point.
Could someone help get me started with this or someone else take this patch from here?
Comment #23
erathina commentedHi,
I tried to use this patch but i dont find any difference after applying. i added the webform submissions data(required date field) in relationships and pulled that as a filter criteria but the fileds are still string and i dont see any greater than or lesser than options. Will this patch only work with module version "7.x-4.x-dev". i am using version "7.x-4.15".
Any help would be appreciated..
Thanks,
Eswaran Rathinam.
Comment #24
meladawy commentedNot working from my side as well, even with adding relationship.
Comment #25
garyg commentedHere is a simple method that will work to filter webform submissions by a webform date field using the PHP_views module.
This example assumes you have already setup your webform relationships in your view.
In this example I am filtering out events with an end date that is in the past.
Just 2 steps to get this working
First you need to find the $data value for the date field you wish to filter on.
To do this, add a (temporary) Global PHP field and in the PHP Output code insert this:
Next add a filter using the Global PHP
If the result of the php is true, the data will be filtered from the view
In the PHP Filter code insert this (change the $data value to what you get in step one)
remove your temporary PHP field from step one and your done.
Comment #26
liam morlandDrupal 7 is no longer supported. If this applies to a supported version, please re-open.