fix(07-01): convert dates back to ISO format before form submission
Added form submit handler that converts DD.MM.YYYY dates back to YYYY-MM-DD format before submission. This fixes validation error "Bewerbungsfrist is invalid" by ensuring Formidable Forms receives dates in the expected format. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -139,7 +139,7 @@ if ( $is_edit_mode ) {
|
||||
});
|
||||
}, 500);
|
||||
|
||||
// Fix date format after user selects a date - replace slashes with dots
|
||||
// Fix date format after user selects a date - replace slashes with dots for display
|
||||
$(document).on('change', 'input[type="date"], input.frm_date', function() {
|
||||
var field = $(this);
|
||||
var value = field.val();
|
||||
@@ -148,9 +148,27 @@ if ( $is_edit_mode ) {
|
||||
if (value && value.includes('/')) {
|
||||
var fixedValue = value.replace(/\//g, '.');
|
||||
field.val(fixedValue);
|
||||
// Store the original format in a data attribute for form submission
|
||||
field.data('original-format', value.replace(/\//g, '-'));
|
||||
console.log('Fixed date format from', value, 'to', fixedValue);
|
||||
}
|
||||
});
|
||||
|
||||
// Before form submission, convert dates back to YYYY-MM-DD format
|
||||
$('form').on('submit', function() {
|
||||
$(this).find('input[type="date"], input.frm_date').each(function() {
|
||||
var field = $(this);
|
||||
var value = field.val();
|
||||
|
||||
// Convert DD.MM.YYYY or DD/MM/YYYY back to YYYY-MM-DD
|
||||
if (value && /^\d{2}[./]\d{2}[./]\d{4}$/.test(value)) {
|
||||
var parts = value.split(/[./]/);
|
||||
var isoDate = parts[2] + '-' + parts[1] + '-' + parts[0];
|
||||
field.val(isoDate);
|
||||
console.log('Converted date for submission from', value, 'to', isoDate);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user