Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rihab 104 posts 388 karma points
    Jul 10, 2019 @ 08:46
    Rihab
    0

    Property Type Validate

    Hi everyone,

    I'm facing a challenge in Extending Umbraco,

    I want to add a validation to my numeric filed, so I created this

        [PropertyEditor("NumericValidator", "Total Numeric", "~/App_Plugins/NumericValidator/NumericValidate.html", ValueType = PropertyEditorValueTypes.Integer)]
    
    public class NumericValidatorPropertyEditorcs : PropertyEditor
    {
        protected override PropertyValueEditor CreateValueEditor()
        {
            var editor = base.CreateValueEditor();
    
            editor.Validators.Add(new NumericValidator());
    
            return editor;
        }
    
    }
    

    and

       internal class NumericValidator : IPropertyValidator
    {
        public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor)
        {
            //throw new NotImplementedException();
            if (value == null || value.ToString().IsNullOrWhiteSpace())
            {
                yield break;
            }
            // int? EventRegisterdSeats = DB_Oprs.ReservedSeats(.Id) == null ? 0 : DB_Oprs.ReservedSeats(item1.Id);
    
            if (value.ToString().Length >= 50)
            {
                yield return new ValidationResult(string.Format("You have more registerd Seats the the Total Number", value),
                                                  new[]
                                                      {
                                                          //we only store a single value for this editor so the 'member' or 'field' 
                                                          // we'll associate this error with will simply be called 'value'
                                                          "value"
                                                      });
            }
        }
    }
    

    but the challenge is that the value I want to compare it with the property value is from DB and based on the current content id! is it possible to get the node id the property is on?.

    can someone guide me on the right path?

    Thanks.

Please Sign in or register to post replies

Write your reply to:

Draft