Пример #1
0
        private void WriteFormPropertyFeedback(List <string> lines, SchemaPropertyInfo property)
        {
            RequiredAttribute RequiredAttribute = property.GetCustomAttribute <RequiredAttribute>();

            if (RequiredAttribute != null)
            {
                lines.Add(string.Format("                                    feedback: \"{{'glyphicon': true, 'glyphicon-ok': hasSuccess(), 'glyphicon-star': !hasSuccess() }}\", "));
            }
            else
            {
                lines.Add(string.Format("                                    feedback: \"{{'glyphicon': true, 'glyphicon-ok': hasSuccess() }}\", "));
            }

            lines.Add(string.Format("                                    htmlClass: 'has-feedback',"));
        }
Пример #2
0
        private void WriteSchemaPropertyValidation(List <string> lines, SchemaPropertyInfo property)
        {
            RequiredAttribute          RequiredAttribute          = property.GetCustomAttribute <RequiredAttribute>();
            RegularExpressionAttribute RegularExpressionAttribute = property.GetCustomAttribute <RegularExpressionAttribute>();
            MaxLengthAttribute         MaxLengthAttribute         = property.GetCustomAttribute <MaxLengthAttribute>();
            MinLengthAttribute         MinLengthAttribute         = property.GetCustomAttribute <MinLengthAttribute>();

            if (RequiredAttribute != null)
            {
                lines.Add(string.Format("                        required: true,"));
            }
            if (RegularExpressionAttribute != null)
            {
                lines.Add(string.Format("                        pattern: \"{0}\",", RegularExpressionAttribute.Pattern));
            }
            if (MaxLengthAttribute != null)
            {
                lines.Add(string.Format("                        maxLength: \"{0}\",", MaxLengthAttribute.Length));
            }
            if (MinLengthAttribute != null)
            {
                lines.Add(string.Format("                        minLength: \"{0}\",", MinLengthAttribute.Length));
            }

            var ValidationAttributes = new List <ValidationAttribute>();

            if (RequiredAttribute != null)
            {
                ValidationAttributes.Add(RequiredAttribute);
            }
            if (RegularExpressionAttribute != null)
            {
                ValidationAttributes.Add(RegularExpressionAttribute);
            }
            if (MaxLengthAttribute != null)
            {
                ValidationAttributes.Add(MaxLengthAttribute);
            }
            if (MinLengthAttribute != null)
            {
                ValidationAttributes.Add(MinLengthAttribute);
            }

            if (ValidationAttributes.Any(p => !string.IsNullOrEmpty(p.ErrorMessage)))
            {
                lines.Add(string.Format("                        validationMessage: {{"));

                if (RequiredAttribute != null)
                {
                    // 302: 'Required',
                    if (!string.IsNullOrEmpty(RequiredAttribute.ErrorMessage))
                    {
                        lines.Add(string.Format("                            302: '{0}',", RequiredAttribute.ErrorMessage));
                    }
                }
                if (RegularExpressionAttribute != null)
                {
                    // 202: 'String does not match pattern: {{schema.pattern}}',
                    if (!string.IsNullOrEmpty(RegularExpressionAttribute.ErrorMessage))
                    {
                        lines.Add(string.Format("                            202: '{0}',", RegularExpressionAttribute.ErrorMessage));
                    }
                }

                if (MaxLengthAttribute != null)
                {
                    // 201: 'String is too long ({{viewValue.length}} chars), maximum {{schema.maxLength}}',
                    if (!string.IsNullOrEmpty(MaxLengthAttribute.ErrorMessage))
                    {
                        lines.Add(string.Format("                            201: '{0}',", MaxLengthAttribute.ErrorMessage));
                    }
                }
                if (MinLengthAttribute != null)
                {
                    // 200: 'String is too short ({{viewValue.length}} chars), minimum {{schema.minLength}}',
                    if (!string.IsNullOrEmpty(MinLengthAttribute.ErrorMessage))
                    {
                        lines.Add(string.Format("                            200: '{0}',", MinLengthAttribute.ErrorMessage));
                    }
                }
                lines.Add(string.Format("                        }},")); // validationMessage
            }
        }