0

アプリケーションでブートストラップに日付ピッカーを使用しています。ここに私のHTMLコードがあります:

<div class="input-append date pull-right" id="dp3" data-date-format="dd-mm-yyyy">
   <input name="dataregisto" id="dataregisto" class="span2" size="16" type="text" readonly>
   <span class="add-on"><i class="icon-th"></i></span>
</div> 

そのため、データを保存すると正常に機能しますが、レコードを編集すると日付が表示されません。一方、残りのデータはすべて入力されます。私の JavaScript コード:

(function($) {
    $(document).ready(function() {
        var today = new Date();
        var t = today.getDate() + "-" + (today.getMonth() + 1) + "-" + today.getFullYear();
        $("#dp3").datepicker()
                .on('show', function(ev) {

            $('#dp3').data({date: t}).datepicker('update');
        });

         //    $('#timepicker1').timepicker();


        document.getElementById("dataregisto").value = document.getElementById("dataregisto").defaultValue = t;
    });

})(jQuery);

コントローラ

 function edit($id = null) {

    session_start();
    if (isset($_SESSION['username'])) { /* verifica se existe uma sessão */
        $this->Registo->id = $id;
        if (empty($this->data)) {
            /* acede aos projetos */
            $this->set('projects', $this->Registo->Project->find('list', array('fields' => array('pname'))));
            /* acede ás versoes do projecto a editar */
            $this->set('projectversions', $this->requestAction("/ProjectVersions/getversionsofproject", array('projects' => $this->Registo->read()['Registo']['projects'])));
            /* acede aos clientes */
            $this->set('clients', $this->requestAction("/CustomFieldOptions/getClients"));
            /* acede ás issuetypes */
            // $issuetype= $this->requestAction("/Projects/getissuetypeofproject", array('projects' => $this->Registo->read()['Registo']['projects']));

            $this->set('dataregisto', $this->Registo->read()['Registo']['dataregisto']);
            /*  $issuetype = array();

              foreach($IssueTypes as $value) {
              $value = $value['IssueType']['id'];
              $issuetype[$value['IssueType']['id']] = $value['IssueType']['pname'];
              }


              debug($issuetype); */

            $this->set('issuetype', $issuetype);
            $this->request->data = $this->Registo->read();
        } else {
            if ($this->Registo->save($this->request->data)) {
                $this->Session->setFlash(__('Registo alterado com sucesso', true), 'flash_success');
                $this->redirect(array('action' => 'index'));
            } else {
                $errors = $this->Registo->invalidFields();
                $this->Messages->customize_error_msg($errors['issuetype']);
            }
        }
    } else {
        $this->redirect(array('controller' => 'users', 'action' => 'login'));
        // $this->Session->setFlash(__('Por favor efetue LOGIN para poder aceder a esta página!', true), 'flash_success');
    }
}

ありがとうございました!

4

1 に答える 1

0

挿入したデータを保存しますか? dd-mm-yyyy 形式の MySQL データベースでは? それが解決策であるか、バグを検出した可能性があります。

編集:ドキュメントを見てください

(function($) {
    $(document).ready(function() {
        var today = new Date(),
t = today.getDate() + "-" + (today.getMonth() + 1) + "-" + today.getFullYear();
        $("#dp3").datepicker().on('show', function(e) {
            e.preventDefault();
            $(this).datepicker('setValue', t);
        });
        document.getElementById("dataregisto").value = document.getElementById("dataregisto").defaultValue = t;
    });
})(jQuery);
于 2013-05-21T10:21:15.587 に答える