##kartik 挂件 [TOC] ### 开关式按钮 ~~~ <?php echo $form->field($model, 'status')->widget(\kartik\widgets\SwitchInput::classname(), [ 'type' => \kartik\widgets\SwitchInput::CHECKBOX ]); ?> <?php echo $form->field($model, 'status')->widget(\kartik\widgets\SwitchInput::classname(), [ 'type' => \kartik\switchinput\SwitchInput::RADIO, 'items' => [ [ 'label' => 'AAAA', 'value' => 0, ], [ 'label' => 'BBBB', 'value' => 1, ], ] ]); ?> ~~~ ### spin 数据输入, 带+ - ~~~ <?php echo \kartik\touchspin\TouchSpin::widget([ 'name' => 'amount', 'options' => ['placeholder' => 'Adjust...'], 'pluginOptions' => [ 'min' => 0, 'max' => 100, 'step' => 0.1, 'decimals' => 2, 'boostat' => 5, 'maxboostedstep' => 10, 'postfix' => '%', 'verticalbuttons' => true ] ]); ?> ~~~ ### 5星投票,图标式输入 ~~~ <?php echo $form->field($model, 'comment')->label('Rate This FAQ')->widget(\kartik\widgets\StarRating::classname(), [ 'pluginOptions' => [ 'size' => 'sm', //xl 'stars' => 5, 'min' => 0, 'max' => 5, 'step' => 0.5, //'showClear' => false, //'showCaption' => false, //'symbol' => html_entity_decode('&#xe005;', ENT_QUOTES, "utf-8"), // 'defaultCaption' => '{rating} hearts', 'starCaptions'=>[], //'displayOnly' => true, //'disabled' => true, //'language' => 'zh-CN', 'filledStar' => '<i class="glyphicon glyphicon-heart"></i>', 'emptyStar' => '<i class="glyphicon glyphicon-heart-empty"></i>', 'defaultCaption' => '{rating} hearts', 'starCaptions' => new \yii\web\JsExpression("function(val){return val == 1 ? 'One heart' : val + ' hearts';}") ] ])?> ~~~ ### 输入单个日期 ~~~ <?php echo $form->field($model, 'created_at')->widget(\kartik\widgets\DatePicker::classname(), [ 'options' => ['placeholder' => 'Select date ...'], //'type' => \kartik\widgets\DatePicker::TYPE_INPUT, 'pluginOptions' => [ 'format' => 'yyyy-mm-dd', 'autoclose' => true, 'todayHighlight' => true ] ]); ?> ~~~ ### 显示2个输入框,分别输入起始日期 ~~~ <?php echo $form->field($model, 'created_at')->widget(\kartik\widgets\DatePicker::classname(), [ 'type' => \kartik\widgets\DatePicker::TYPE_RANGE, 'attribute2' => 'updated_at', 'options' => ['placeholder' => 'Start date'], 'options2' => ['placeholder' => 'End date'], 'form' => $form, 'pluginOptions' => [ 'format' => 'yyyy-mm-dd', 'autoclose' => true, 'todayHighlight' => true ] ]); ?> ~~~ ### 时分秒输入 ~~~ <?php echo $form->field($model, 'created_at')->widget(\kartik\widgets\TimePicker::classname(), [ 'pluginOptions' => [ //'showSeconds' => true, 'showMeridian' => false, 'minuteStep' => 5, ] ]); ?> ~~~ ### 时分秒输入