logo
down
shadow

How to tell if a cell value has passed validation


How to tell if a cell value has passed validation

By : user2955208
Date : November 22 2020, 10:38 AM
Any of those help Specific answer to your question, there is no method within Google Apps Script that will return the validity of a Range such as .isValid(). As you state, you could reverse engineer a programatic one using Range.getDataValidations() and then parsing the results of that in order to validate again the values of a Range.getValues() call.
It's a good suggestion. I've added a feature request to the issue tracker -> Add a Star to vote it up.
code :


Share : facebook icon twitter icon
Silverlight validation red outline stays around element whose data has passed validation, until focused and blurred

Silverlight validation red outline stays around element whose data has passed validation, until focused and blurred


By : Robert Taylor
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Implementing INotifyDataErrorInfo, rather than IDataErrorInfo, seemed to do the trick. IDataErrorInfo is nice but lacks the ability to let the UI know when other properties have changed besides the current one. I tried allowing both implementations but it got a bit weird, so I changed it so it only implemented INotifyDataErrorInfo.
code :
    public class Guardian : ModelBase, /*IDataErrorInfo,*/ INotifyDataErrorInfo
    {

        internal Guardian()
        {

        }

        [Required]
        [StringLength(50)]
        [Display(Name = "Guardian's First Name")]
        public string FirstName
        {
            get { return GetValue(() => FirstName); }
            set { SetValue(() => FirstName, value); }
        }

        [Required]
        [StringLength(50)]
        [Display(Name = "Guardian's Last Name")]
        public string LastName
        {
            get { return GetValue(() => LastName); }
            set { SetValue(() => LastName, value); }
        }

        [USPhoneNumber]
        [Display(Name = "Home Phone Number")]
        public string HomePhone
        {
            get { return GetValue(() => HomePhone); }
            set { SetValue(() => HomePhone, value.NormalizeNANPPhoneNumber()); }
        }

        [USPhoneNumber]
        [Display(Name = "Personal Cell")]
        public string PersonalCell
        {
            get { return GetValue(() => PersonalCell); }
            set { SetValue(() => PersonalCell, value.NormalizeNANPPhoneNumber()); }
        }

        [Required]
        [StringLength(100)]
        [Display(Name = "Address")]
        public string Address1
        {
            get { return GetValue(() => Address1); }
            set { SetValue(() => Address1, value); }
        }

        [StringLength(100)]
        public string Address2
        {
            get { return GetValue(() => Address2); }
            set { SetValue(() => Address2, value); }
        }

        [Required]
        [StringLength(100)]
        public string City
        {
            get { return GetValue(() => City); }
            set { SetValue(() => City, value); }
        }

        [Required]
        [StringLength(100)]
        public string State
        {
            get { return GetValue(() => State); }
            set { SetValue(() => State, value); }
        }

        [Required]
        [StringLength(20)]
        [USPostalCode]
        [Display(Name = "ZIP Code")]
        public string Zip
        {
            get { return GetValue(() => Zip); }
            set { SetValue(() => Zip, value); }
        }

        [Required]
        [Display(Name = "Relationship to Children")]
        public FamilyRole Relationship
        {
            get { return GetValue(() => Relationship); }
            set { SetValue(() => Relationship, value); }
        }

        internal bool IsEmpty()
        {
            return
                string.IsNullOrWhiteSpace(FirstName)
                && string.IsNullOrWhiteSpace(LastName)
                && string.IsNullOrWhiteSpace(HomePhone)
                && string.IsNullOrWhiteSpace(PersonalCell)
                && string.IsNullOrWhiteSpace(Address1)
                && string.IsNullOrWhiteSpace(Address2)
                && string.IsNullOrWhiteSpace(City)
                && string.IsNullOrWhiteSpace(State)
                && string.IsNullOrWhiteSpace(Zip)
                && Relationship == null
                ;
        }

        protected override void PropertyHasChanged(string propertyName)
        {
            base.PropertyHasChanged(propertyName);
            if (ErrorsChanged != null)
                this.GetType().GetProperties().ToList().ForEach(p => ErrorsChanged(this, new DataErrorsChangedEventArgs(p.Name)));
        }

        /// <summary>
        /// Provides support for cross-cutting concerns without having to write
        /// an attribute in Silverlight.
        /// When time allows, convert to an Attribute. The code produced then
        /// can be reused in other projects.
        /// </summary>
        /// <param name="listToAddTo"></param>
        private void CustomValidation(List<ValidationResult> listToAddTo)
        {
            if (listToAddTo == null)
                throw new ArgumentNullException("listToAddTo");
            if (string.IsNullOrWhiteSpace(HomePhone) && string.IsNullOrWhiteSpace(PersonalCell))
                listToAddTo.Add(new ValidationResult("At least one phone number must be filled in.", new string[] { "HomePhone", "PersonalCell" }));
        }

        List<ValidationResult> getErrorList()
        {
            List<ValidationResult> results = new List<ValidationResult>();
            this.IsValidObject(results);
            CustomValidation(results);
            return results;
        }

        /*
        #region IDataErrorInfo Members

        public string Error
        {
            get
            {
                List<ValidationResult> results = getErrorList();
                if (results.Count > 0)
                    return results[0].ErrorMessage;
                else
                    return null;
            }
        }

        public string this[string columnName]
        {
            get
            {
                List<ValidationResult> results = getErrorList();
                var resultByColumn = results.Where(r => r.MemberNames.Contains(columnName)).ToList();
                if (resultByColumn.Count > 0)
                    return resultByColumn[0].ErrorMessage;
                else
                    return null;
            }
        }

        #endregion
         */

        #region INotifyDataErrorInfo Members

        public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;

        public System.Collections.IEnumerable GetErrors(string propertyName)
        {
            List<ValidationResult> results = getErrorList();
            return results.Where(e => e.MemberNames.Contains(propertyName));
        }

        public bool HasErrors
        {
            get 
            {
                List<ValidationResult> results = getErrorList();
                return results.Count > 0;
            }
        }

        #endregion
    }
listToAddTo.Add(new ValidationResult("At least one phone number must be filled in.", new string[] { "HomePhone", "PersonalCell" }));
namespace CLARIA.Infrastructure
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;

    /// <summary>
    /// Builds upon ModelBase with built-in validation.
    /// </summary>
    public abstract class ValidatableModelBase : ModelBase,
    #if SILVERLIGHT
        INotifyDataErrorInfo
    #else
        IDataErrorInfo
    #endif

    {

        private List<ValidationResult> GetErrorList()
        {
            List<ValidationResult> results = new List<ValidationResult>();
            this.IsValidObject(results);
            CustomValidation(results);
            return results;
        }

        /// <summary>
        /// Allows the derived class to override and add custom validation.
        /// The validation results generated from this method should be added
        /// to the collection <see cref="addResultsToThisList"/>.
        /// </summary>
        /// <param name="addResultsToThisList"></param>
        protected virtual void CustomValidation(List<ValidationResult> addResultsToThisList) {}

    #if SILVERLIGHT

        #region INotifyDataErrorInfo Members

        protected override void PropertyHasChanged(string propertyName)
        {
            base.PropertyHasChanged(propertyName);
            // Force re-validation of every property.
            if (ErrorsChanged != null)
                this.GetType().GetProperties().ToList().ForEach(p => ErrorsChanged(this, new DataErrorsChangedEventArgs(p.Name)));
        }

        public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;

        public System.Collections.IEnumerable GetErrors(string propertyName)
        {
            List<ValidationResult> results = GetErrorList();
            return results.Where(e => e.MemberNames.Contains(propertyName));
        }

        public bool HasErrors
        {
            get
            {
                List<ValidationResult> results = GetErrorList();
                return results.Count > 0;
            }
        }

        #endregion

    #else

        #region IDataErrorInfo Members

        public string Error
        {
            get
            {
                List<ValidationResult> results = GetErrorList();
                if (results.Count > 0)
                    return results[0].ErrorMessage;
                else
                    return null;
            }
        }

        public string this[string columnName]
        {
            get
            {
                List<ValidationResult> results = GetErrorList();
                var resultByColumn = results.Where(r => r.MemberNames.Contains(columnName)).ToList();
                if (resultByColumn.Count > 0)
                    return resultByColumn[0].ErrorMessage;
                else
                    return null;
            }
        }

        #endregion

    #endif


    }

    }
how can i move a way from a dataGridView cell even when the cell value has not passed validation?

how can i move a way from a dataGridView cell even when the cell value has not passed validation?


By : reza
Date : March 29 2020, 07:55 AM
like below fixes the issue I am validating cell values in an unbound dataGridView control but am not liking the behaviour am getting.
code :
if (!string.IsNullOrEmpty(e.FormattedValue.ToString()) &&
    !decimal.TryParse(e.FormattedValue.ToString(), out qty))
{
    e.Cancel = true;
    ...
}
How to test whether or not a cell has passed data validation?

How to test whether or not a cell has passed data validation?


By : Kerem
Date : March 29 2020, 07:55 AM
This might help you Unfortunately I just found out that there is no way to check if a cell is valid in another post (that I somehow missed when searching for this answer).
The official request to Google is here. Please go comment and star for this useful method to be added to Google Apps Script!
Macro To Clear Contents of a Data Validation Cell IF Specific Cell Formula Changes it's Value

Macro To Clear Contents of a Data Validation Cell IF Specific Cell Formula Changes it's Value


By : Eric
Date : March 29 2020, 07:55 AM
wish of those help Try this in the worksheet's private code sheet (right-click worksheet name tab and choose View Code),
code :
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("N6")) Is Nothing Then
        application.enableevents = false
        Range("N8") = vbnullstring
        application.enableevents = true
    End If

End Sub
How to make url validation without http ( or add it after validation passed )?

How to make url validation without http ( or add it after validation passed )?


By : Pavel B
Date : March 29 2020, 07:55 AM
hope this fix your issue Please don't use regexes for this. Don't even use the same regex that the jQuery validator uses, it may change in the future and you won't be able to take advantage of the updates. This is the way to do this:
shadow
Privacy Policy - Terms - Contact Us © ourworld-yourmove.org