1
I Use This!
Activity Not Available

News

Posted about 11 years ago by Zikiro
Hi, I've to validate de following quite complex scenery (at least for me :D). Let's say: public class CLASSA { public ItemSelectorEnum ItemSelector {get; set; } public object Item {get; set;} } public enum ItemSelectorEnum { TypeA ... [More] , TypeB } public class TypeAClass { public string TypeAClassProp {get; set;} } public class TypeBClass { public string TypeAClassProp {get; set;} } So, when ItemSelector is TypeA then Item must be of TypeAClass, and when ItemSelector is TypeB, Item must be of class TypeBClass I've to do this way because it's a implementation of an XSD implementation (SEPA Direct Debit) I'm trying to check validations using FV (of course :D) public class ClassAValidator : AbstractValidator<ClassA> { public ClassAValidator() { When(c => c.ItemSelector == ItemSelectorEnum.TypeA), () => { RuleFor(c => c.Item).SetValidator(new TypeAClassValidator()); } [same for TypeBClass] } Intellisense is ok, but when I try to Test, I get the following error: Message: Unable to create instance of class Test Error: System.InvalidOperationException: The validator 'TypeAClassValidator' cannot validate members of type 'Object' - the types are not compatible.. How can I make those validation types? KR Zikiro [Less]
Posted about 11 years ago by mattritchie
Thanks for clarifying! I completely understand why you'd not want to maintain old versions. We're currently stuck on .net 4.0, as our servers are win2k3. We are currently planning our server upgrades, as there's so much we are missing out on now. Cheers, Matt
Posted about 11 years ago by JeremyS
You can change this globally by setting the static property ValidatorOptions.DisplayNameResolver
Posted about 11 years ago by phroos
Hi! First - love the framework, the functionality provided and what it can do is outstanding. But - I second this, the wish for an option controlling how this behaves (on global level, or on AbstractValidator baseclass level?). I have multiple ... [More] rules, some with quite an amount of custom rules - and my readability lessens with each .WithName I have to use. /Many regards, and thank you for an an outstanding validation framework, Philip [Less]
Posted about 11 years ago by JeremyS
Simplest thing to do would be to use a method group: public class MyValidator : AbstractValidator<Category> { public MyValidator(){ RuleFor(x=>x.Description).Must(BeUniqueDescription); } private bool BeUniqueDescription(Category ... [More] category, string description) { // put logic for calling sproc in here. Return true or false depending on the sproc's result } } [Less]
Posted about 11 years ago by enigmae
Hello, Thank you for making such an awesome framework. I have an odd requirement where I need to call out to a stored proc (via EF) passing in an output parameter (or two). I need to validate the response of this. I want to do this via the fluent ... [More] / RuleFor logic, but am not seeing a straight forward approach. It looks like it might need some nested Func<T>'s but here is the gist of the logic This is my standard validation logic var outputParameter = new System.Data.Entity.Core.Objects.ObjectParameter("isUnique", typeof(bool)); databaseContext_validate_unique_name(description, outputParameter); if (outputParameter.Value != null) { if ((bool)outputParameter.Value == false) { //throw exception as the name is not unique throw new ArgumentException(ErrorMessages.NameIsNotUnique()); } } I was trying something like so RuleFor(category => category.Description) .Must(description => "1".Equals("call Sproc from here and get output variable?")) .WithMessage("Error: description must be unique!"); Any help would be greatly appreciated. Thanks, [Less]
Posted about 11 years ago by JeremyS
Hi Matt No plans for another update I'm afraid. FV 5.2 was the last to include mvc4 support. Because of the very poor extensibility points in MVC, and the subtle changes between versions it's a massive pain to support MVC at all (let alone multiple ... [More] versions), and unfortunately I don't have the time to do this anymore, so going forward, FV will only support the latest version of MVC. If all you're using is the CopyToModelState extension, then it definitely makes senses to just include this method in your project if you want to use FV 5.3 with MVC 4. The difficulty comes if you want to try and use the model binder integration, which is a real mess. Hope that makes sense, sorry if it's a disappointing answer. Jeremy [Less]
Posted about 11 years ago by mattritchie
Hi, Just trying to update to FV to 5.3 with FV.MVC4. MVC4 is hardcoded to depend only on 5.1 to 5.2 Is there an update coming for this package? I've worked out i was just using the AddToModelState extension method, so i've extracted that from the repo so i can keep working with the new version of FV. Cheers, Matt
Posted about 11 years ago by ItsMeSri
I need to validate two textboxes based on dropdownselect. It is dependency validation. for this I am using FluentValidation. Key thing is here, values of dropdownlist is language specification. (Russia, spanish). ```RuleFor(x => ... [More] x.HasMaterialPublishedElseWhereText).NotEmpty().WithMessage(i18n_Models_Abstract.RequiredField); RuleFor(x => x.DtPublishedTimeText).NotEmpty().When(x => x.HasMaterialPublishedElseWhereText == i18n_Models_Abstract.AbstractYes).WithMessage(i18n_Models_Abstract.RequiredField); RuleFor(x => x.PublishedPlaceText).NotEmpty().When(x => x.HasMaterialPublishedElseWhereText == i18n_Models_Abstract.AbstractYes).WithMessage(i18n_Models_Abstract.RequiredField);```__view--__```<div class="row" style="padding-bottom: 10px"> <div class="col-md-10"> <div class="col-md-4"> @Html.HiddenFor(model => model.HasMaterialPublishedElseWhereOptions) @{ options = Model.HasMaterialPublishedElseWhereOptions; optionsList = options.Split(',').ToList(); optionSelect = optionsList.Select(option => new SelectListItem() { Text = option, Value = option }).ToList(); } @Html.DropDownListFor(model => model.HasMaterialPublishedElseWhereText, optionSelect, i18n_Models_Abstract.SelectOption +"...", new { @class = "input-validation-error form-control" }) @Html.ValidationMessageFor(model => model.HasMaterialPublishedElseWhereText) </div> </div> </div> <div class="row" style="padding-bottom: 10px"> <div class="col-md-10"> <div class="col-md-4"> @Html.TextBoxFor(model => model.DtPublishedTimeText, new { @class = "form-control", @placeholder = Model.DtPublishedTimeLabel, maxlength = 40 }) @Html.ValidationMessageFor(model => model.DtPublishedTimeText) </div> </div> </div> <div class="row" style="padding-bottom: 10px"> <div class="col-md-10"> <div class="col-md-4"> @Html.TextBoxFor(model => model.PublishedPlaceText, new { @class = "form-control", @placeholder = Model.PublishedPlaceLabel, maxlength = 40 }) @Html.ValidationMessageFor(model => model.PublishedPlaceText) </div> </div> </div>``` HTML--``` <div class="col-md-4"> <input id="HasMaterialPublishedElseWhereOptions" name="HasMaterialPublishedElseWhereOptions" type="hidden" value="да/yes,нет/no"> <select class="input-validation-error form-control" data-val="true" data-val-required="обязательное поле" id="HasMaterialPublishedElseWhereText" name="HasMaterialPublishedElseWhereText"> <option value="">Выбрать опции...</option> <option selected="selected" value="да/yes">да/yes</option> <option value="нет/no">нет/no</option> </select> <span class="field-validation-valid" data-valmsg-for="HasMaterialPublishedElseWhereText" data-valmsg-replace="true"></span> </div> <div class="col-md-4"> <input class="form-control" id="DtPublishedTimeText" maxlength="40" name="DtPublishedTimeText" placeholder="Если Да, укажите дату публикации/If yes, Date" type="text" value=""> <span class="field-validation-valid" data-valmsg-for="DtPublishedTimeText" data-valmsg-replace="true"></span> </div> <div class="col-md-4"> <input class="form-control" id="PublishedPlaceText" maxlength="40" name="PublishedPlaceText" placeholder="" type="text" value=""> <span class="field-validation-valid" data-valmsg-for="PublishedPlaceText" data-valmsg-replace="true"></span> </div>```![enter image description here][1]All other validation are working, except this dependency one not working? Anything doing wrong? [1]: http://i.stack.imgur.com/PV21u.png [Less]
Posted about 11 years ago by JeremyS
Hello,I've made a translation of error messages to Danish. Attached is the patch file (diff to commit 4555a33). Hope it can be useful.