Add custom class to CakePHP automagic date select

拈花ヽ惹草 提交于 2020-01-25 20:22:24

问题


I would like to add a class to all selects of an automagic created datepicker formgroup.

<?= $this->Form->input('hide', ['class'=>'classtoadd' ]); ?>

The result ist:

<div class="input date">
    <label>Hide</label>
    <select name="hide[year]">
        <option value="" selected="selected"></option>
        <option value="2020">2020</option>
        ...
    </select>
    <select name="hide[month]">
        <option value="" selected="selected"></option>
        <option value="01">Januar</option>
        ...
    </select>
    <select name="hide[day]">
        <option value="" selected="selected"></option>
        <option value="01">1</option><option value="02">2</option>
    </select>
</div>

The class classtoadd is simply missing from the selects. This workes perfectly on simple inputs. Is this an expected behaviour or am I doing something wrong?

Im using cakephp 3.0.8.

Thanks!


回答1:


echo $this->Form->time('released', [
    'interval' => 15,
    'hour' => [
        'class' => 'foo-class',
    ],
    'minute' => [
        'class' => 'bar-class',
    ],
]);

prints=>

<select name="released[hour]" class="foo-class">
    <option value="" selected="selected"></option>
    <option value="00">0</option>
    <option value="01">1</option>
    <!-- .. snipped for brevity .. -->
    <option value="22">22</option>
    <option value="23">23</option>
</select>
<select name="released[minute]" class="bar-class">
    <option value="" selected="selected"></option>
    <option value="00">00</option>
    <option value="15">15</option>
    <option value="30">30</option>
    <option value="45">45</option>
</select>

Reference - Cakebook3.x



来源:https://stackoverflow.com/questions/31318376/add-custom-class-to-cakephp-automagic-date-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!