klox7 VIP
Total posts: 914
03 Dec 2013 05:31

I'm trying to configure date field (template on the form is simple select) in a way so when user selects year it won't be able to select years from now (in 2013 the last year from select would be 2013, in 2014 would be 2014 and so on). Any suggestions? Regards

Last Modified: 02 Mar 2014


Sergey
Total posts: 13,748
04 Dec 2013 01:31

Can you describe idea in whole. I mean what is your site idea. I cannot understand. I mean I understand what you described but I cannot understand practically application. What if I add article 31 December 2013 and say 1 year from now. It is 2012 but tomorrow it will be 2013. What idea will fit this behaviour?


klox7 VIP
Total posts: 914
04 Dec 2013 02:49

The idea is to use that kind of field in record review. Site is travel based with travel accomodations. Field is called "When were you there?" In select option I don't want user to be able to select "in 2017" and therefore give my reviews uncredibility.


Sergey
Total posts: 13,748
04 Dec 2013 05:04

Do you mean that user select year 2013 and field show This year or Last year if it is 2014?


klox7 VIP
Total posts: 914
04 Dec 2013 05:23

Field can show value as it is - if user selects 7.12.2013 than can be shown like that. But if you can do what you said it's also great. How?

But I would just like to limit select values shown during the selection of date. If user makes review right now (on 4th Dec 2013) then he can't select 2014 in year input because he couldn't be there in 2014. He can only select dates from the past not future.


Sergey
Total posts: 13,748
04 Dec 2013 07:43

I read it few times but still have not grasped the concept.

Please see input template parameter in the field parameters. There have to mbe manual input. That are selects.


Sergey
Total posts: 13,748
04 Dec 2013 07:44

Another way is to use select field and insert years there. And then create custom output template to display whatever you like.


klox7 VIP
Total posts: 914
04 Dec 2013 08:21

Yes I guess will use select field and control output of the template. I'm attaching picture of what I meant.


Sergey
Total posts: 13,748
05 Dec 2013 00:36

If you create select field you can insert manual values. Anyway either you use select field or datetime field with select input template you can change template to adjust.

Like in your screenshot. You would have to copy input template and edit it so that only earst till current are in the list.


klox7 VIP
Total posts: 914
05 Dec 2013 07:59

To remove future years: If I copy components/com_cobalt/fields/datetime/tmpl/input/simple_select.php and change line 53 from

for($i = (date('Y') + 10); $i >= date('Y') - 80; $i --) :

to

for($i = (date('Y')); $i >= date('Y') - 20; $i --) :

would that be ok?

And if I remove selection of days would something else stop working?

<select class="date_list" style="width:50px" name="jform[fields][<?php echo $this->id;?>][0][day]">

    <option value="0"><?php echo  JText::_('D_DAY');?></option>

    <?php

    $selected = $s_value ? date('j', $s_value) : 0;

    for($i = 1; $i <= 31; $i ++) :

    ?>

    <option value="<?php echo $i;?>" <?php if($i == $selected) echo 'selected';?>><?php echo $i;?></option>

    <?php endfor; ?>

</select>

Sergey
Total posts: 13,748
06 Dec 2013 01:25

I am not sure this is correct approach. This field will need date to be stored. Use simple "select field". Then you can save simply year. And in output template use this year to calculate anything.


klox7 VIP
Total posts: 914
06 Dec 2013 01:47

Aham, OK. Will do with simple select. I just hope in 2015 I will remember to put 2015 in year field:). Thanks.


Sergey
Total posts: 13,748
10 Dec 2013 09:27

You do not need to put it there. You can create input template as well where you get current year, and cycle 20 times back

$year = date('Y');

for($year; $year > $year - 20; $year--)

{

$options[] = JHtml::_('select.option', $year, $year);

}

echo JHtml::_('select.genericlist', $options, ..........)

Powered by Cobalt