如何在Yii2中仅在年份中选择daterangepicker?

时间:2015-10-18 20:28:13

标签: twitter-bootstrap datepicker yii2 daterangepicker

我在YII 2中需要有关boostrap daterangepicker的帮助。我需要仅以年份格式更改选择范围。我正在使用https://github.com/kartik-v/yii2-date-range

我需要选择日期2000-2005,1990-2000 ....只有没有月份和日期的年份。我只在基本bootstrap datepicker中找到了这个选项。

3 个答案:

答案 0 :(得分:2)

到目前为止,您尝试实施了哪些内容,以便我们可以为您提供更多帮助,并在您的问题中添加一些也会有所帮助的代码。

我建议您尝试#include <stdio.h> #include <stdlib.h> struct node { int* data; struct node *next; }; struct node* Addrear(struct node *list, int* d) ; void PrintList(struct node *list); int main( ) { struct node *pList=NULL; int number[4]; number[0] = 1; number[1] = 2; number[2] = 3; number[3] = 4; pList = Addrear( pList, number ); // Print everything out. printf("items in linked list\n"); PrintList (pList); system("PAUSE"); return 1; } // Pre-condition: list points to the head of a linked list. // Post-condition: returns a pointer to the new head of a linked list that // adds a node with d to the end of the original list. struct node* Addrear(struct node *list, int* d) { struct node *pNew = NULL; struct node *current = NULL; // Create the new node. pNew = (struct node*)malloc(sizeof(struct node)); memcpy(pNew->data, d, 4*sizeof*d); pNew->next = NULL; // Store front of the linked list current = list; // if list is empty then this becomes the first node. if (list == NULL) return pNew; // Iterate so that current points to the last node in the list. while (current ->next != NULL) current = current->next; // Link the last node to the new node. current->next = pNew; // Return a pointer to the edited list. return list; } // Pre-condition: list points to the head of a linked list. // Post-condition: Prints out each item in the list pointed to by list, in order. void PrintList( struct node *list) { // Iterate through each item and print it! while (list != NULL) { printf("-->%d", list->data); list = list->next; } printf("\n"); } 并尝试停用月份和日期视图 并访问kartik的网站,其中提供了文档,并阅读顶部的选项,作为第三方工具,而不是它可能有限制,可能会在小部件的官方网站上解释更多

希望这有帮助

答案 1 :(得分:2)

查看插件的documentation Kartik widget基于做你想做的事情似乎不可能,但是Yii2已经有了这个功能built in:< / p>

1,添加此css以隐藏除年份

之外的日历小部件上的所有内容
['CC', '123', ':....:']

2,使用内置的Yii小部件,更改类/型号名称以反映您的实际项目

<style type="text/css">
.ui-datepicker-calendar {
        display: none;
    }
</style>

3,在测试中我发现我必须添加这个javascript(但可能有更好的方法)

echo $form->field($model, 'time_scheduled')->widget(\yii\jui\DatePicker::classname(), [

    'clientOptions' => [

        'changeMonth' => false,
        'changeYear' => true,
        'showButtonPanel' => true,
        'dateFormat' => 'yyyy',
        'yearRange' => '1990:2020'
    ],
]);

Yii正在使用bootstrap日期选择器,其中的选择是here

答案 2 :(得分:1)

echo DatePicker::widget([
'model' => $model,
'attribute' => 'start_date',
'options' => ['placeholder' => 'Start date'],
'type' => DatePicker::TYPE_COMPONENT_PREPEND,
'form' => $form,
'pluginOptions' => [
'format' => 'mm/yyyy',
'autoclose' => true,
'minViewMode' => 1,
]
]);