Skip to content

Commit 38a6379

Browse files
committed
feat: add datetime specific options
1 parent 51a6dbf commit 38a6379

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/Html/Editor/Fields/DateTime.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,59 @@ public function minutesAvailable(array $minutes): static
109109
{
110110
return $this->opts(['minutesAvailable' => $minutes]);
111111
}
112+
113+
/**
114+
* The format of the date string loaded from the server for the field's
115+
* value and also for sending to the server on form submission.
116+
* The formatting options are defined by Moment.js.
117+
*
118+
* @param string $format
119+
* @return $this
120+
* @see https://editor.datatables.net/reference/field/datetime#Options
121+
* @see https://momentjs.com/docs/#/displaying/format/
122+
*/
123+
public function wireFormat(string $format = 'YYYY-MM-DDTHH:mm:ss.000000Z'): static
124+
{
125+
$this->attributes['wireFormat'] = $format;
126+
127+
return $this;
128+
}
129+
130+
/**
131+
* Allow (default), or disallow, the end user to type into the date / time input element.
132+
* If disallowed, they must use the calendar picker to enter data. This can be useful
133+
* if you are using a more complex date format and wish to disallow the user from
134+
* potentially making typing mistakes, although note that it does also disallow
135+
* pasting of data.
136+
*
137+
* @param bool $state
138+
* @return $this
139+
* @see https://editor.datatables.net/reference/field/datetime#Options
140+
* @see https://momentjs.com/docs/#/displaying/format/
141+
*/
142+
public function keyInput(bool $state = true): static
143+
{
144+
$this->attributes['keyInput'] = $state;
145+
146+
return $this;
147+
}
148+
149+
/**
150+
* The format of the date string that will be shown to the end user in the input element.
151+
* The formatting options are defined by Moment.js. If a format is used that is not
152+
* ISO8061 (i.e. YYYY-MM-DD) and Moment.js has not been included, Editor will
153+
* throw an error stating that Moment.js must be included for custom
154+
* formatting to be used.
155+
*
156+
* @param string $format
157+
* @return $this
158+
* @see https://editor.datatables.net/reference/field/datetime#Options
159+
* @see https://momentjs.com/docs/#/displaying/format/
160+
*/
161+
public function displayFormat(string $format = 'YYYY-MM-DD hh:mm a'): static
162+
{
163+
$this->attributes['displayFormat'] = $format;
164+
165+
return $this;
166+
}
112167
}

0 commit comments

Comments
 (0)