From 5d13afd8f6c1ec479e20b8aa0f2a44368e7f2bd0 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Fri, 8 May 2015 14:54:53 +0000 Subject: [PATCH] Make sure visitor name is not empty in prechat survey --- .../js/source/chat/models/survey/survey_form.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/mibew/js/source/chat/models/survey/survey_form.js b/src/mibew/js/source/chat/models/survey/survey_form.js index eac5746f..f4bddfed 100644 --- a/src/mibew/js/source/chat/models/survey/survey_form.js +++ b/src/mibew/js/source/chat/models/survey/survey_form.js @@ -61,6 +61,18 @@ * @param Object attributes Attributes hash for test */ validate: function(attributes) { + // Check visitor's name + if (this.get('canChangeName') && typeof attributes.name != 'undefined') { + var trimmedName = attributes.name + // Remove leading spaces from the name + .replace(/^\s+/, '') + // Remove trailing spaces from the name + .replace(/\s+$/, ''); + if (trimmedName.length === 0) { + return Mibew.Localization.trans('Name is required.'); + } + } + // Check email if (this.get('showEmail')) { if (typeof attributes.email != 'undefined') {