Hi!
For the sake of consistency I’d like to use the browser-native date- and time pickers if possible. So I duplicated and renamed npDateTpl
, removed all the JS and changed the type to date and time, resp.:
<div id="np-[[+npx.fieldName]]-container" class="np-date">
[[+np.error_[[+npx.fieldName]]]]
<label class="fieldlabel" for="[[+npx.fieldName]]" title="[[+npx.help]]">[[+npx.caption]]:</label>
<div class = "np-date-hints"><span class = "np-date-hint"> [[%np_date_hint]]</span><span class ="np-time-hint">[[%np_time_hint]]</span></div>
<input type="date" id="[[+npx.fieldName]]" name="[[+npx.fieldName]]" maxlength="10" value="[[+np.[[+npx.fieldName]]]]" />
<input type="time" class="[[+npx.fieldName]]_time" name="[[+npx.fieldName]]_time" id="[[+npx.fieldName]]_time" maxlength="10" value="[[+np.[[+npx.fieldName]]_time]]" />
<div class="invalid_date" id="[[+npx.fieldName]]_date_error" style="visibility:hidden">[[%np_invalid_date]]</div>
</div>
This works for storing time and date in the TV, but the fields are not filled out correctly afterwards when someone wants to review or change the data. The reason is the format the date is returned by using
[[+np.[[+npx.fieldName]]]]
. This returns YYYYMMDD, whereas the type=date input needs YYYY-MM-DD
So I thought I could use a quick and dirty output modifier and insert the dashes with that:
<?php
$output = substr($input,0,4)."-".substr($input,4,2)."-".substr($input,6,2);
return $output;
This works when the name of the date-time-TV is used explicitly:
[[+np.e-datumzeit:reformatDate]]
But not when used like this:
[[+np.[[+npx.fieldName]]:reformatDate]]
in fact the MODX parser returns the value of a totally different TV. I also tried all combinations of calling the placeholders cached: no success.
So is this a bug in the MODX parser/caching, in Newspublisher or (most likely) in my brain?
Jörg