0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Moodle Form API - date_selector

Last updated at Posted at 2019-01-03

Moodle Form APIのdate_selectorで初期値設定どうやるの???:worried:って一瞬なったのでdate_selectorまわりのメモ。

コード

moodleform::setDefaultの第2引数にタイムスタンプ入れると任意の日付を初期値にできます。

ファイルの配置
plugintype/
 └ pluginname/
   │ classes/
   │ └ form/
   │   └ my_form.php
   └ view.php
my_form.php
<?php

namespace plugintype_pluginname\form;

require_once($CFG->libdir . '/formslib.php');

class my_form extends \moodleform {
    public function definition() {
        $mform = $this->_form;

        list($year, $month, $day) = [2018, 10, 31];
        $mform->addElement('date_selector', 'date_selector_1', 'Label1');
        $mform->setDefault('date_selector_1', make_timestamp($year, $month, $day));
        $mform->addElement('date_selector', 'date_selector_2', 'Label2');
    }
}

表示例

初期値を指定しなかった場合、ページを開いた日(語弊あるかも?)が入ります。

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?