This commit is contained in:
@@ -35,8 +35,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start_date">Start Date (optional)</label>
|
<label for="start_date_picker">Start Date (optional)</label>
|
||||||
<input type="datetime-local" id="start_date" name="start_date" class="form-control">
|
<input type="datetime-local" id="start_date_picker" class="form-control">
|
||||||
|
<input type="hidden" id="start_date" name="start_date">
|
||||||
<div class="form-hint">When the hunt becomes active. Leave blank to start immediately.</div>
|
<div class="form-hint">When the hunt becomes active. Leave blank to start immediately.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -47,8 +48,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="expiry_date">Expiry Date (optional)</label>
|
<label for="expiry_date_picker">Expiry Date (optional)</label>
|
||||||
<input type="datetime-local" id="expiry_date" name="expiry_date" class="form-control">
|
<input type="datetime-local" id="expiry_date_picker" class="form-control">
|
||||||
|
<input type="hidden" id="expiry_date" name="expiry_date">
|
||||||
<div class="form-hint">Leave blank for no expiry.</div>
|
<div class="form-hint">Leave blank for no expiry.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -58,13 +60,12 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Convert datetime-local (user's local time) to UTC ISO before submit
|
|
||||||
document.querySelector('form').addEventListener('submit', function() {
|
document.querySelector('form').addEventListener('submit', function() {
|
||||||
['start_date', 'expiry_date'].forEach(function(name) {
|
[['start_date_picker', 'start_date'], ['expiry_date_picker', 'expiry_date']].forEach(function(pair) {
|
||||||
var input = document.getElementById(name);
|
var picker = document.getElementById(pair[0]);
|
||||||
if (input && input.value) {
|
var hidden = document.getElementById(pair[1]);
|
||||||
var d = new Date(input.value);
|
if (picker.value) {
|
||||||
if (!isNaN(d)) input.value = d.toISOString();
|
hidden.value = new Date(picker.value).toISOString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -31,8 +31,9 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="start_date">Start Date (optional)</label>
|
<label for="start_date">Start Date (optional)</label>
|
||||||
<input type="datetime-local" id="start_date" name="start_date" class="form-control"
|
<input type="datetime-local" id="start_date_picker" class="form-control"
|
||||||
data-utc="<%= hunt.start_date || '' %>">
|
data-utc="<%= hunt.start_date || '' %>">
|
||||||
|
<input type="hidden" id="start_date" name="start_date">
|
||||||
<div class="form-hint">When the hunt becomes active. Leave blank to start immediately.</div>
|
<div class="form-hint">When the hunt becomes active. Leave blank to start immediately.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -44,8 +45,9 @@
|
|||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="expiry_date">Expiry Date (optional)</label>
|
<label for="expiry_date">Expiry Date (optional)</label>
|
||||||
<input type="datetime-local" id="expiry_date" name="expiry_date" class="form-control"
|
<input type="datetime-local" id="expiry_date_picker" class="form-control"
|
||||||
data-utc="<%= hunt.expiry_date || '' %>">
|
data-utc="<%= hunt.expiry_date || '' %>">
|
||||||
|
<input type="hidden" id="expiry_date" name="expiry_date">
|
||||||
<div class="form-hint">Leave blank for no expiry.</div>
|
<div class="form-hint">Leave blank for no expiry.</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -54,7 +56,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// Populate datetime-local inputs from stored UTC values (convert to local)
|
// Populate datetime-local pickers from stored UTC values (convert to local)
|
||||||
document.querySelectorAll('input[data-utc]').forEach(function(input) {
|
document.querySelectorAll('input[data-utc]').forEach(function(input) {
|
||||||
var utc = input.dataset.utc;
|
var utc = input.dataset.utc;
|
||||||
if (utc) {
|
if (utc) {
|
||||||
@@ -65,13 +67,13 @@ document.querySelectorAll('input[data-utc]').forEach(function(input) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// Convert datetime-local (user's local time) to UTC ISO before submit
|
// Convert picker local time to UTC ISO for hidden inputs on submit
|
||||||
document.querySelector('form').addEventListener('submit', function() {
|
document.querySelector('form').addEventListener('submit', function() {
|
||||||
['start_date', 'expiry_date'].forEach(function(name) {
|
[['start_date_picker', 'start_date'], ['expiry_date_picker', 'expiry_date']].forEach(function(pair) {
|
||||||
var input = document.getElementById(name);
|
var picker = document.getElementById(pair[0]);
|
||||||
if (input && input.value) {
|
var hidden = document.getElementById(pair[1]);
|
||||||
var d = new Date(input.value);
|
if (picker.value) {
|
||||||
if (!isNaN(d)) input.value = d.toISOString();
|
hidden.value = new Date(picker.value).toISOString();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user