0

Symfony2 のフォーム datetime minutes フィールドのリスト値を制限する方法を知りたいです。解説は以下の通りです。

フォームの日時フィールドの分フィールドのコンボ ボックスをクリックすると、以下のスクリーン ショットのように値のリストが表示されます。

ここに画像の説明を入力

上記でわかるように、分のフィールド リストの値は 00 から 59 です (日時の形式を 'dd/MM/yyyy H:i' としています)。ちなみに、これはフォームクラスのコードです:

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder

        ->add('title','text')
        ->add('start','datetime',array(
         'input' => 'datetime',

         'format' => 'dd/MM/yyyy H:i',))
        ->add('end','datetime',array(
         'input' => 'datetime',

         'format' => 'dd/MM/yyyy H:i',))

        ->add('location','text')
        ->add('description','text')

    ;
}

そして、これはフォームの html コードです:

    <html>
    <head>
        <title> Wkayet </title>
         <link rel="shortcut icon" href="{{asset('bundles/ikprojhome/images/icon-WKAYET.png')}}">
        <link rel="stylesheet" type="text/css" href="{{asset('bundles/ikprojhome/css2/css.css')}}"/>
        <script src='{{asset('bundles/ikprojhome/lib/jquery.min.js')}}'></script> 

    </head>
    <body>
    <center>
        <div id="container">
            <div id="header">

            </div>
            <div id="content">
                <table width="100%" height="100%" align="center">
                    <tr>
                        <td>
                            {% for x in groupe%}
   <form id="EventForm" action='{{path('ikproj_groupe_homepaeventsAdd',{id:x['id']})}}' method="POST" {{ form_enctype(form) }} onsubmit="javascript:parent.jQuery.fancybox.close();">
   <!--<form id="EventForm" action='{{path('ikproj_groupe_homepaeventsAdd',{id:x['id']})}}' method="POST" {{ form_enctype(form) }} >-->
                                {% endfor %}
                                 {{ form_errors(form) }}
                                <table align="center">
                                    <tr>
                                        <td class="separation"><label for="groupname">Titre</label></td>
                                        <td>
                                     <!--<input id="titre" name="titre" required="required" type="text" size="50"/> -->
                                         <div>
                                            {{ form_errors(form.title) }}

                                            {{ form_widget(form.title) }}
                                           </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="separation"><label for="debut">Début</label></td>
                                        <td><!--<select id="debut" name="debut" class="select"></select>-->
                                            <div>
                                             {{ form_errors(form.start ) }}

                                             {{ form_widget(form.start ) }}
                                            </div>


                                        </td>
                                    </tr>
                                    <tr>
                                        <td class="separation"><label for="fin">Fin</label></td>
                                        <td><!--<select id="fin" name="fin" class="select"></select>-->
                                            <div>
                                             {{ form_errors(form.end ) }}

                                             {{ form_widget(form.end ) }}
                                          </div> 

                                        </td>
                                    </tr>

                                    <tr>
                                        <td class="separation"><label for="lieu">Lieu</label></td>
                                        <td> 

                                         <div>
                                           {{ form_errors(form.location) }}

                                           {{ form_widget(form.location) }}
                                          </div>

                                        </td>
                                    </tr>
                                    <tr>
                                        <td id="description" valign="top" class="separation"><label for="description">Description</label></td>
                                        <td><textarea id="ikproj_groupebundle_eventsgroupe_description" name="ikproj_groupebundle_eventsgroupe[description]" rows="5" cols="40"></textarea> 



                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" align="center" id="button" valign="bottom"><input class="button" type="submit" value=""/></td>
                                    </tr>
                                </table>
                                         {{form_widget(form._token)}} 
                            </form>
                        </td>
                    </tr>
                </table> 
            </div>
        </div>
    </center>
</body>
</html>

だから、私の質問は、分フィールドに特定の値を含めるにはどうすればよいですか? (たとえば、次の 2 つの値が含まれています: 00 と 30 )..それを行うことは可能ですか??

4

1 に答える 1

1

Symfony のTimeTypeは基本的に拡張された選択フィールドであり、DateTimeType使用しているTimeType. 'minutes'したがって、次のようなパラメーターを渡すことができるはずです。

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('title', 'text')
        ->add('start', 'datetime', array(
         'input' => 'datetime',
         'format' => 'dd/MM/yyyy H:i',
         'minutes' => array(
            0,
            30
         )
        ))
        ->add('end', 'datetime', array(
         'input'  => 'datetime',
         'format' => 'dd/MM/yyyy H:i',
         'minutes' => array(
            0,
            30
         )
        ))
        ->add('location', 'text')
        ->add('description', 'text')
    ;
}

これを説明するドキュメントは次のとおりです: http://symfony.com/doc/current/reference/forms/types/time.html#minutes

于 2014-09-01T10:02:00.457 に答える