The generic warning message seems to be ok except the part with the datestring. Datestring should be presented same as in the input field and not as iso datestring. Is that possible somehow to correct it?
Invalid expression message with a datetime-local field does not format the date in warning message
created 9 months ago
(modified 9 months ago)
Answers approved by surveyjs Support
Hello Wolfgang,
In the future we will introduce the ability to format text input using our mask that is currently in beta. We are working on date time mask right now.
Your task could be solved by using survey.onGetQuestionDisplayValue event:
JavaScriptfunction formatDate(str) {
const date = new Date(str);
return (
('00' + date.getDate()).slice(-2) +
'.' +
('00' + (date.getMonth() + 1)).slice(-2) +
'.' +
date.getFullYear() +
' ' +
('00' + date.getHours()).slice(-2) +
':' +
('00' + date.getMinutes()).slice(-2) +
':' +
('00' + date.getSeconds()).slice(-2)
);
}
const survey = new Survey.Model(json);
survey.onGetQuestionDisplayValue.add((sender, options) => {
const q = options.question;
if (!q.isEmpty() &&q.getType() === 'text' && q.inputType === 'datetime-local') {
options.displayValue = formatDate(q.value);
}
});
You can modify formatDate function as you need.
Here is the working example.
Thank you,
Andrew
SurveyJS Team
Hello Wolfgang,
I created this demo and confirmed that the date appears in a specified format:
I would appreciate it if you could share a problematic demo for research.
Thanks
{ "logoWidth": "auto", "logoHeight": "40", "pages": [ { "name": "Overview", "elements": [ { "type": "panel", "name": "Survey", "elements": [ { "type": "expression", "name": "OVSurveyAdministratorsLabel", "maxWidth": "50%", "title": { "default": "Administratoren", "en": "Administrators" }, "titleLocation": "left", "descriptionLocation": "underInput", "readonlyRenderAs": "text", "useGrouping": false }, { "type": "html", "name": "OVSurveyAdministrators", "startWithNewLine": false, "title": "Administratoren", "titleLocation": "top", "html": "{OVSurveyAdministrators}" }, { "type": "expression", "name": "OVSurveyParticipantsCount", "maxWidth": "50%", "title": { "default": "Teilnehmer gesamt:", "en": "Total participants:" }, "titleLocation": "left", "descriptionLocation": "underInput", "defaultValueExpression": "'0'", "readonlyRenderAs": "text", "useGrouping": false }, { "type": "expression", "name": "OVSurveyResultsCount", "maxWidth": "50%", "startWithNewLine": false, "title": { "default": "Ergebnisse gesamt:", "en": "Total results:" }, "titleLocation": "left", "descriptionLocation": "underInput", "defaultValueExpression": "'0'", "readonlyRenderAs": "text" }, { "type": "text", "name": "SurveyDateFrom", "title": { "default": "Laufzeit von:", "en": "Valid from:" }, "titleLocation": "left", "descriptionLocation": "underInput", "errorLocation": "bottom", "validators": [ { "type": "expression", "text": { "en": "The 'Valid from' date must be sooner than the 'Valid until' date!", "default": "Das 'Laufzeit von' Datum muss früher als das 'Laufzeit bis' Datum sein!" }, "expression": "iif({SurveyDateUntil} empty, true, iif({SurveyDateFrom} empty, true, (getDate({SurveyDateFrom}) < getDate(({SurveyDateUntil})))))" } ], "inputType": "datetime-local" }, { "type": "text", "name": "SurveyDateUntil", "minWidth": "", "startWithNewLine": false, "title": { "default": "Laufzeit bis:", "en": "Valid until:" }, "titleLocation": "left", "descriptionLocation": "underInput", "errorLocation": "bottom", "validators": [ { "type": "expression", "text": { "en": "The 'Valid until' date must be later than the 'Valid from' date!", "default": "Das 'Laufzeit bis' Datum muss später als das 'Laufzeit von' Datum sein!" }, "expression": "iif({SurveyDateFrom} empty, true, iif({SurveyDateUntil} empty, true, (getDate({SurveyDateUntil}) > getDate({SurveyDateFrom}))))" } ], "inputType": "datetime-local" } ], "title": { "default": "Umfrage", "en": "Survey" }, "startWithNewLine": false, "width": "100%", "minWidth": "256px", "showQuestionNumbers": "off" }, { "type": "panel", "name": "VisualizationPanel", "elements": [ { "type": "radiogroup", "name": "SurveyVisualizer", "useDisplayValuesInDynamicTexts": false, "width": "350px", "title": { "default": "Auswertung/Report", "en": "Report" }, "titleLocation": "top", "descriptionLocation": "underInput", "defaultValueExpression": "'survey-table'", "choices": [ { "value": "survey-analytics", "text": { "default": "Analyse-Dashboard", "en": "Analytics-Dashboard" } }, { "value": "survey-table", "text": { "default": "Einfache Tabelle", "en": "Table" } } ], "colCount": 0 }, { "type": "radiogroup", "name": "SurveyResultType", "width": "350px", "title": { "default": "Anonymität", "en": "Anonymity" }, "titleLocation": "top", "descriptionLocation": "underInput", "defaultValueExpression": "'private'", "renderAs": "radio", "choices": [ { "value": "private", "text": { "default": "Ja", "en": "Yes" } }, { "value": "public", "text": { "default": "Nein", "en": "No" } } ], "colCount": 0 } ], "title": { "default": "Visualisierung", "en": "Visualization" }, "showQuestionNumbers": "off" } ] } ], "completeText": { "default": "Speichern", "en": "Complete" }, "widthMode": "static", "width": "860" }