I created a date cck field, where the user shall select a year (from a select list). I want the user can choose years from 2001 to present. But I can only select "Years back and forward". If I choose "7 years back", it shows me 2001, but next year the select list will show me 2002, right? But I want it to stay to start with 2001. What to do?
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | 307274-15.date-range-valid.patch | 1.47 KB | ksenzee |
Comments
Comment #1
no2e commentedCan somebody help me, please?
Comment #2
no2e commentedHelp please :|
I want the users to choose from
2001 to the current year - and that future proof. They shall never be able to select 2000 but shall everytime be able to select the current year.
Comment #3
tancI've also encountered the same problem. I've created my form in a module and I can only see '#date_year_range' => '-7:0' as a possibility. This doesn't let me restrict the date to a specific beginning year, just 7 years before this year. I want it to start in 2003 as the earliest date, as the data I'm using begins then.
Anyone have any ideas how to override this and insert a specific list?
Comment #4
Alice Heaton commented@Tanc : Had the same issue ; it seems to me that if you created your own form, then you can simply set :
Unless the values of your form are cached (I don't think this happens in Drupal) then you're fine.
@no2e : I'm afraid the only thing I can think of would be for you to write a small custom module, implement hook_form_alter ; look for the right element and set #date_year_range as above.
Sorry - I do realize this is a difficult task if you've never done it before, but I can't think of anything else... Or hope the module maintainer will implement this feature at some point...
Comment #5
arlinsandbulte commentedSeems like a reasonable feature request to me.
Maybe provide a UI similar to the one in views filters where you can choose between absolute and relative.
Two values needed to provide a date range, sort of like a to-from date.
For instance, your date range could be:
between now-3years and now+3years (this is the current default)
between 2001 and now+3years
between 2001 and now
between 2001 and 2005
Maybe this could be expanded to include days and times as well, making it very generic.
Marking this as feature request and moving to HEAD.
Comment #6
extexan commentedI'm using the Date module, but not with CCK (just the Date API in my own module), so I don't know if this will help you... But I've been able to put in absolute dates by omitting the minus (-) and plus (+) signs. The only anomaly I've found is that years have to be four digits, so if you want a range of year 500 to year 3000 (for example) it would have to be entered as "0500:3000". I haven't tried an absolute "from" year with a relative "to" year, so I don't know if you will be able to handle the "year 2001 to current year +3" requirement. Hope this helps.
Comment #7
gargsuchi commentedAnd what if I want my date limit to be next month?? cant i do that??
Basically, i want the user to be able to chose a date, but that date cant be beyond 1 month from now. How can i do this??
Comment #8
puya commentedI have the same problem, I'm trying to set the date cck filed so that the TO date can only go as far as +30 hrs from the FROM date.. I would really appreciate any help on this.
Comment #9
KerriO commentedI would love to see this actually become as granular as selecting a specific day for + and -.
I create a lot of event submission forms, where it's a week or month long event and people submit specific entries for these events. It would be nice to only allow the selectable area to fall between the exact date range that I specify.
Comment #10
karens commentedThe current code allows for either the +- or a fixed year, so the following work in both D6 and D7 versions of Date:
- '-100:+10'
- '2001:+3';
- '2000:2020';
- '-10:2020'
The code also automatically expands the year to include a default value if a default value is set. So if you have a range that would end up as 1990-1999 and you have a default value of a date in 2010, the range will end up being 1990-2010. That bit is needed because the default value always has to be a valid value in the range.
As for getting more granular than year, that is a different and much more difficult request.
Comment #11
CatherineOmega commentedKarenS: I can't get that to work in the latest release of Date. Just to confirm, is that something I can put in "Years back and forward" when configuring a Date CCK field, or did I miss something? When I hit "Save", drupal_set_message says "Years back and forward must be in the format -9:+9."
Comment #12
dkhill commentedI am having the same issue. No matter what format I use:
-1:+1
0:+1 (Which is the one that I had before the module was upgraded).
I even added a period as in the example:
0:+1.
0:+2.
Etc, etc. All comes back with the same error message. (Somethings' broken).
Comment #13
pauljr8 commentedBelieving in due diligence but realizing when enough is enough, I am unable to limit or modify in any way the date year range. Not that it's not possible, but this being my first module I am learning this amazing platform. I've been a drupaler for several years, since version 3 I believe but I intend to learn its true power. Anyway, after 5 days, of searching, buying Pro Drupal 7 development and alienating my family. I need help on how to limit the date year field. This has to be one of the best kept secrets ever for something that is so common. below is one of the myriad attempts to affect the year portion of the field.
drupal-7.x-dev
date-7.x-2.x-dev
$form['renter']['birthday'] = array(
'#type' => 'date',
'#title' => 'Date of Birth',
'#date_format' => 'm-d-Y',
'#date_label_position' => 'within',
'#date_year_range' => '-100:+0',
);
Comment #14
pauljr8 commentedNever mind. I had my head buried for so long I didn't see that everyone else was talking about date_select and date_popup while my code said date. It works fine. Time to venture into more unfamiliar form territory.
Comment #15
ksenzeeI'm seeing the same thing as CatherineOmega. It looks to me like the regex in date_range_valid() specifically excludes absolute years. Here's a patch that allows both absolute and relative years, with tests to make sure the regex works.
Comment #16
karens commentedAh yes, I broke this when I tightened up the validation in a recent issue. I'll take a look later today.
Comment #17
karens commentedLooks good, this is now committed. Thanks so much!
Comment #18
roball commentedBut this bug still exists in the latest 6.x version - please fix that branch too.
Comment #19
karens commentedComment #20
roball commentedIs somebody working on the back-ported patch? Seems that it could not be too difficult since this behaviour was already working in a previous 6.x-2.x release.
Comment #21
roball commentedAny update on this?
Comment #22
arlinsandbulte commentedI will work on porting the patch when I get a chance....
Comment #23
roball commentedExcellent, thank you arlinsandbulte.
Comment #24
arlinsandbulte commentedOK, I manually applied #15 to the D6 branch, including the tests and everything seemed ok. Tests passed & it to worked in my testing.
Committed: http://drupalcode.org/project/date.git/commit/5629d20
This will be in the next -dev realease and the next -stable after that.
Comment #26
roball commentedThank you, can confirm that this is working fine with Date 6.x-2.8.