custom-validators

Custom validation on nested attributes

跟風遠走 提交于 2021-02-19 04:03:08
问题 I need to find a way to get rails (3.2.8) to save nested attributes before performing validation on the parent object. I've searched a long time for an answer to my problem and, while I've found similar questions, I haven't yet seen an elegant solution. Here's the situation: I have an activity_log where each log_entry has multiple activities. The log_entry has a field called 'hours', which represents the total time worked that day. Each activity also has an 'hours' field, representing time

How to test a Validator which implements ConstraintValidator in java?

冷暖自知 提交于 2020-08-04 02:36:13
问题 I have an "AllowedValuesValidator.java" class: public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, String> { String[] values; String defaultValue; @Override public void initialize(AllowedValues constraintAnnotation) { values = constraintAnnotation.allowedValues(); defaultValue = constraintAnnotation.defaultValue(); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.isEmpty(defaultValue) && StringUtils.isEmpty

How to test a Validator which implements ConstraintValidator in java?

…衆ロ難τιáo~ 提交于 2020-08-04 02:32:47
问题 I have an "AllowedValuesValidator.java" class: public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, String> { String[] values; String defaultValue; @Override public void initialize(AllowedValues constraintAnnotation) { values = constraintAnnotation.allowedValues(); defaultValue = constraintAnnotation.defaultValue(); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.isEmpty(defaultValue) && StringUtils.isEmpty

How to test a Validator which implements ConstraintValidator in java?

為{幸葍}努か 提交于 2020-08-04 02:32:37
问题 I have an "AllowedValuesValidator.java" class: public class AllowedValuesValidator implements ConstraintValidator<AllowedValues, String> { String[] values; String defaultValue; @Override public void initialize(AllowedValues constraintAnnotation) { values = constraintAnnotation.allowedValues(); defaultValue = constraintAnnotation.defaultValue(); } @Override public boolean isValid(String value, ConstraintValidatorContext context) { if (!StringUtils.isEmpty(defaultValue) && StringUtils.isEmpty

Validation type names in unobtrusive client validation rules must be unique. The following validation type was seen more than once: required

北城以北 提交于 2020-01-24 00:29:22
问题 I created custom ASP.Net MVC model validation as the following: internal class LocalizedRequiredAttribute : RequiredAttribute, IClientValidatable { public List<string> DependentProperties { get; private set; } public List<string> DependentValues { get; private set; } public string Props { get; private set; } public string Vals { get; private set; } public string RequiredFieldValue { get; private set; } public LocalizedRequiredAttribute(string resourceId = "") { if (string.IsNullOrEmpty

WCF custom username and password validation is not executed

十年热恋 提交于 2019-12-24 11:53:49
问题 I have a WCF service hosted on IIS 7.5 with the settings of basicHttpBinding binding and TransportWithMessageCredential security. I would like to send a FaultException to the client in case of failed authentication but unfortunately the Validate method of custom validator class is not executed. I have read here, that custom validator works only for self-hosting scenario: Is it true, or I made a mistake somewhere? public class ServiceUserNamePasswordValidator : UserNamePasswordValidator {

Testing custom validators with Minitest

守給你的承諾、 提交于 2019-12-23 18:59:00
问题 I have multiple models with email validation. Therefore I've extracted the validation into a custom validator. I dit this by following the tutorial of the Rails Guides. class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i record.errors[attribute] << (options[:message] || "is not an email") end end end So far, so good. But since I've extracted the functionality of email validation into it's

Inject custom service into a custom Validator

为君一笑 提交于 2019-12-20 12:39:08
问题 I'm trying to make a custom Angular 2 form Validator to check if a user exist on a data base. This is the code of my custom form Validator import { FormControl } from '@angular/forms'; import {API} from "../services/api"; import {ReflectiveInjector} from "@angular/core"; export class EmailValidator { constructor() {} static checkEmail(control: FormControl,): any { let injector = ReflectiveInjector.resolveAndCreate([API]); let api = injector.get(API); return api.checkUser(control.value).then

Custom validation in MVC not executing on partial views

一曲冷凌霜 提交于 2019-12-20 07:19:13
问题 So I have file uploading input which is strongly typed and below is the model class public class UploadImageAlbum { [CustomFileValidator] public HttpPostedFileBase Images { get; set; } } and my CustomFileValidator class is as below: [AttributeUsage(AttributeTargets.Property,AllowMultiple =true,Inherited =false)] public class CustomFileValidator : ValidationAttribute { protected override ValidationResult IsValid(object value, ValidationContext context) { const int maxContent = 1024 * 1024 * 50

Izpack: Validator doesn't work?

血红的双手。 提交于 2019-12-13 16:07:15
问题 I have a field description in my "UserInputSpec.xml" file. <field type="radio" variable="selected.source" > <description align="left" txt="Please select TBPAPIIntegrator data source:" id="combo.text" /> <spec> <choice txt="IMKB Server" id="combo.item.imkb" value="imkb"/> <choice txt="Exernal Database" id="combo.item.database" value="db"/> </spec> <validator class="com.j32bit.installer.validator.SelectSourceValidator" txt="Please select one source!" > <param name="selected.source" value="$