Skip to content

Instantly share code, notes, and snippets.

@jenswittmann
Last active September 4, 2025 13:15
Show Gist options
  • Select an option

  • Save jenswittmann/1ba37a98a1d6553a9c65662d92f6021d to your computer and use it in GitHub Desktop.

Select an option

Save jenswittmann/1ba37a98a1d6553a9c65662d92f6021d to your computer and use it in GitHub Desktop.
MODX ContentBlocks Custom Input Date Type Plugin
<?php
if ($modx->event->name == 'ContentBlocks_RegisterInputs') {
class cbDateInput extends cbBaseInput
{
public $defaultIcon = 'snippet_B';
public $defaultTpl = '';
public function getTemplates()
{
$tpls = [];
$template = <<<HTML
<div class="contentblocks-loader"></div>
<div class="contentblocks-field contentblocks-field-cbdateinput">
<div class="contentblocks-field-actions"></div>
<label for="{%=o.generated_id%}_textfield">{%=o.name%}</label>
<div class="contentblocks-field-text">
<input type="datetime-local" value="{%=o.value%}">
</div>
</div>
HTML;
$tpls[] = $this->contentBlocks->wrapInputTpl('cbdateinput', $template);
return $tpls;
}
public function getName()
{
return 'Datum';
}
public function getDescription()
{
return 'HTML5 Datumsfeld';
}
}
$instance = new cbDateInput($contentBlocks);
$modx->event->output([
'cbdateinput' => $instance
]);
}
if ($modx->event->name == 'OnDocFormPrerender') {
$script = <<<HTML
<script>
(function ($, ContentBlocks) {
ContentBlocks.fieldTypes.cbdateinput = function(dom, data) {
var input = {};
input.init = () => {};
input.getData = () => {
return {
value: dom.find('input').val()
}
};
return input;
}
})(vcJquery, ContentBlocks);
</script>
<style>
.contentblocks-field input[type=datetime-local] {
line-height: 20px;
padding: 8px;
height: auto;
border-radius: 2px;
display: block;
width: 100%;
position: relative;
background-color: #fbfbfb;
border: 1px solid #ccc;
transition: border-color .25s;
font: normal 13px arial, tahoma, helvetica, sans-serif;
}
</style>
HTML;
$modx->regClientStartupHTMLBlock($script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment