许多日期检查员以一种形式yii2 [英] Many datepickers in one form yii2
问题描述
<?php
for($ i = 0; $ i< 4; $我++){
?>
< div class =row>
< div class =col-md-1>
<?=($ i + 1)。'''>
< / div>
< div class =col-md-3>
<?= $ form->字段($ pres_rules [$ i],'date') - > textInput()?>
< / div>
< div class =col-md-3>
<?=
$ form-> field($ pres_rules [$ i],'time') - > widget(TimePicker :: className(),[
'pluginOptions' => [
'showMeridian'=> false,
'defaultTime'=> '12:00'
],
'addonOptions'=& $ b'asButton'=> true,
]
]);
?>
< / div>
< / div>
<?php
}
?>
结果如下:
只有第一个字段显示时钟图标,我可以点击并选择小时。其余的就像普通文本字段,点击时钟图标不会触发任何进一步的动作。我可以把任何我想要的字符串,字段接受它,只有第一个工作字段拒绝信件等。这里有什么问题?
编辑
我认为问题是Yii为每个字段生成相同的ID。我该怎么改呢?我尝试所有这些,但根本不起作用:
$ form->字段($ pres_rules [$ i ],'time',['inputOptions'=> ['id'=>'time - '。$ i]]) - > widget(TimePicker :: className(),[
'pluginOptions' => [
'id'=>'time-'$ i,
'showMeridian'=> false,
'defaultTime'=> '12:00'
],
'addonOptions'=> [
'asButton'=> true,
],
'containerOptions'=> [
' id'=>'time-'$ i,
],
'id'=>'time - '$ i
],['id'=>时间 - '。$ i,]);
以下是我要更改的ID
,所以你的代码应该是这样的:
<?php foreach($ pres_rules as $ i => $ pres_rule):?>
<?= $ form->字段($ pres_rule,[$ i] date) - >小部件(TimePicker :: className(),[
'pluginOptions'=>
'showMeridian'=> false,
'defaultTime'=> '12:00'
],
'addonOptions'=> [
'asButton '=> true,
]
])?>
<?php endforeach; ?>
I would like to have various datepickers in my form. Unfortunetely, only the first field acts as supposed. Here's my code:
<?php
for ($i = 0; $i < 4; $i++) {
?>
<div class="row">
<div class="col-md-1">
<?= ($i+1).'.' ?>
</div>
<div class="col-md-3">
<?= $form->field($pres_rules[$i], 'date')->textInput() ?>
</div>
<div class="col-md-3">
<?=
$form->field($pres_rules[$i], 'time')->widget(TimePicker::className(), [
'pluginOptions' => [
'showMeridian' => false,
'defaultTime' => '12:00'
],
'addonOptions' => [
'asButton' => true,
]
]);
?>
</div>
</div>
<?php
}
?>
And the result looks like that:
Only the first field shows clock icon, which I can click on and select hours. The rest is like ordinary text fields, clicking on the 'clock icon' doesn't trigger any further action. I can put any string I want and field accepts it, only the first, working field rejects letters etc. What is the problem here?
EDIT
I think the problem is that Yii generates the same IDs for every field. How can I change that? I tried all of these, but doesn't work at all:
$form->field($pres_rules[$i], 'time', ['inputOptions' => ['id' => 'time-'.$i]])->widget(TimePicker::className(), [
'pluginOptions' => [
'id' => 'time-' . $i,
'showMeridian' => false,
'defaultTime' => '12:00'
],
'addonOptions' => [
'asButton' => true,
],
'containerOptions' => [
'id' => 'time-' . $i,
],
'id' => 'time-'.$i
], ['id' => 'time-'.$i,]);
Here's the ID I'd like to change
Please see the documentation about Tabular input http://www.yiiframework.com/doc-2.0/guide-input-tabular-input.html so your code should look like this:
<?php foreach ($pres_rules as $i => $pres_rule): ?>
<?= $form->field($pres_rule, "[$i]date")->widget(TimePicker::className(), [
'pluginOptions' => [
'showMeridian' => false,
'defaultTime' => '12:00'
],
'addonOptions' => [
'asButton' => true,
]
]) ?>
<?php endforeach; ?>
这篇关于许多日期检查员以一种形式yii2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!