protected override bool RealValidate(IResponsePredefinedQuestionProvider elementToValidate, QuestionnaireDto questionnaire, ref Boolean isLengthCorrect, ref string incorrectLengthMsg) { bool hasElement = false; bool hasEmptyElements = false; List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); List<int> validationHints = null; if (responses != null && responses.Count > 0) { foreach (ResponseDto response in responses) { PredefinedQuestionResponseDto questionResponse = response as PredefinedQuestionResponseDto; if (questionResponse != null) { hasElement = true; if (String.IsNullOrEmpty(questionResponse.ChoiceText)) { hasEmptyElements = true; break; } else { if (questionResponse.ChoiceText.Length > 4000) { validationHints = new List<int>(); validationHints.Add(PageElementWithErrorDto.InvalidInputTooLong); } } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Choices validator does not accept a response of type \"" + response.GetType().Name + "\""); } } } bool retval = false; if (validationHints == null) { if (elementToValidate.PageQuestion.Required) { if (!hasEmptyElements && hasElement) { retval = true; } } else { retval = true; } } else { elementToValidate.SetValidationHints(validationHints); } elementToValidate.IsValid = retval; return retval; }
protected override bool RealValidate(IResponsePredefinedQuestionProvider elementToValidate, QuestionnaireDto questionnaire, ref Boolean isLengthCorrect, ref string incorrectLengthMsg) { bool hasElements = false; bool hasMissingTexts = false; isLengthCorrect = true; List<ResponseDto> responses = elementToValidate.GetResponseDto(-1); if (responses != null && responses.Count > 0) { List<PagePredefinedQuestionChoiceDto> choices = elementToValidate.PageQuestionChoices; if (choices == null || choices.Count < 1) { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissing, "Drop down validator requires choices to validate"); } if (responses != null && responses.Count > 0) { foreach (ResponseDto response in responses) { PredefinedQuestionResponseDto questionResponse = response as PredefinedQuestionResponseDto; if (questionResponse != null) { hasElements = true; PredefinedLocalizedChoiceDto pChoice = PredefinedQuestionFacade.GetPredefinedLocalizedChoiceByPagePredefinedChoiceId(questionResponse.ChoiceId); if (pChoice != null && pChoice.PChoiceDto != null) { if (pChoice.PChoiceDto.SortSequence == -1 && elementToValidate.PageQuestion.Required) { hasMissingTexts = true; } if (pChoice.PChoiceDto.SortSequence == 999 && !String.IsNullOrEmpty(pChoice.OtherText) && !String.IsNullOrEmpty(pChoice.ErrorMessage)) { if (String.IsNullOrEmpty(questionResponse.ChoiceText)) { hasMissingTexts = true; } else { if (questionResponse.ChoiceText.Length > 4000) { incorrectLengthMsg = pChoice.ErrorMessage; hasMissingTexts = true; isLengthCorrect = false; } } } } } else { throw new UserCausedException(Constants.UserCausedDataFormatIncorrectElementMissmatch, "Choices validator does not accept a response of type \"" + response.GetType().Name + "\""); } } } } bool retval = false; if (elementToValidate.PageQuestion.Required) { if (hasElements) { if (!hasMissingTexts && isLengthCorrect) { retval = true; } } } else { if (!(hasMissingTexts) && isLengthCorrect) { retval = true; } } elementToValidate.IsValid = retval; return retval; }