0

i have 2 input forms, the "Date From" and "Date To" , both are using jquery's date picker My question is, how to limit the user to select only a range of one month using those two datepickers ?

this is the snippet of the "Date From" date picker

                $this->widget('zii.widgets.jui.CJuiDatePicker',
                        array(
                                'model' => $model,
                                'attribute' => 'STARTDATE',
                                'options' => array(
                                        'dateFormat'=>'yy-mm-dd',
                                        'showOn'=> 'both',
                                        'buttonImage'=> Yii::app()->theme->baseUrl."/images/calendar.gif",
                                        'buttonImageOnly' => 'true',
                                        'dateFormat'=>'dd-mm-yy',
                                        'changeMonth' => 'true',
                                        'changeYear' => 'true',
                                        'showButtonPanel' => 'true',
                                        'constrainInput' => 'false',
                                        'duration'=>'fast',
                                        'showAnim' =>'slide',
                                        'ampm' => 'true',
                                        'onSelect' => 'js:function(selectedDate) {$( "#paymenttrans_TRANSDATETO" ).datepicker( "option", "minDate", selectedDate );}'
                                ),
                                'flat'=>false,
                                'htmlOptions'=>array(
                                'readonly'=>'TRUE',
                                'size'=>'10',
                                'style'=>'margin-right: 5px;'
                                )
                        )
                );

the objective is like this, let's say the user selects date from January 1 to February 1, that's it, if the user tries to select that has a range of more than 1 month , it should be prevented...how to do that?

sasori
  • 5,249
  • 16
  • 86
  • 138
  • You can fetch the date of both field, compare it and if it's more then a month display a error on the screen. You can just use regular javascript for that. I don't know if there is a 'simple' jquery solution – Matthijs Jul 29 '13 at 12:56
  • Use jquery for this. Also you can make custom rule with validation in model and add clientside validation to activeform, but this is more efficient. – ineersa Jul 29 '13 at 13:17
  • I need a formula how to compute the chosen date range is exact one month – sasori Jul 29 '13 at 14:07

1 Answers1

1

Here Solution would give you an Idea of how to find Diff in Months,

Difference in Months

Community
  • 1
  • 1
shiva kumar
  • 74
  • 1
  • 5