1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.Components
.Validator
18 using System
.Collections
;
21 /// Ensures that a property was
22 /// filled with some value
25 public class NonEmptyValidator
: AbstractValidator
28 /// Check that this property has a value that is not null or empty (if string)
30 /// <param name="instance"></param>
31 /// <param name="fieldValue"></param>
32 /// <returns><c>true</c> if the field is OK</returns>
33 public override bool IsValid(object instance
, object fieldValue
)
35 return fieldValue
!= null && fieldValue
.ToString().Length
!= 0;
39 /// Gets a value indicating whether this validator supports browser validation.
42 /// <see langword="true"/> if browser validation is supported; otherwise, <see langword="false"/>.
44 public override bool SupportsBrowserValidation
50 /// Applies the browser validation by setting up one or
51 /// more input rules on <see cref="IBrowserValidationGenerator"/>.
53 /// <param name="config">The config.</param>
54 /// <param name="inputType">Type of the input.</param>
55 /// <param name="generator">The generator.</param>
56 /// <param name="attributes">The attributes.</param>
57 /// <param name="target">The target.</param>
58 public override void ApplyBrowserValidation(BrowserValidationConfiguration config
, InputElementType inputType
,
59 IBrowserValidationGenerator generator
, IDictionary attributes
,
62 base.ApplyBrowserValidation(config
, inputType
, generator
, attributes
, target
);
64 generator
.SetAsRequired(target
, BuildErrorMessage());
68 /// Returns the key used to internationalize error messages
71 protected override string MessageKey
73 get { return MessageConstants.IsRequiredMessage; }