<commit_before>using System;
using System.Collections.Generic;
using System.Linq;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Runtime;
using DotVVM.Framework.Hosting;

namespace DotVVM.Framework.Controls
{
    /// <summary>
    /// Displays all validation messages from the current Validation.Target.
    /// </summary>
    [ControlMarkupOptions(AllowContent = false)]
    public class ValidationSummary : HtmlGenericControl
    {
        
        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationSummary"/> class.
        /// </summary>
        public ValidationSummary()
        {
            TagName = "ul";
        }


        /// <summary>
        /// Gets or sets whether the errors from child objects in the viewmodel will be displayed too.
        /// </summary>
        [MarkupOptions(AllowBinding = false)]
        public bool IncludeErrorsFromChildren
        {
            get { return (bool) GetValue(IncludeErrorsFromChildrenProperty); }
            set { SetValue(IncludeErrorsFromChildrenProperty, value); }
        }
        public static readonly DotvvmProperty IncludeErrorsFromChildrenProperty
            = DotvvmProperty.Register<bool, ValidationSummary>(c => c.IncludeErrorsFromChildren, false);


        /// <summary>
        /// Gets or sets whether the errors from the <see cref="Validation.TargetProperty"/> object will be displayed too.
        /// </summary>
        [MarkupOptions(AllowBinding = false)]
        public bool IncludeErrorsFromTarget
        {
            get { return (bool) GetValue(IncludeErrorsFromTargetProperty); }
            set { SetValue(IncludeErrorsFromTargetProperty, value); }
        }
        public static readonly DotvvmProperty IncludeErrorsFromTargetProperty
            = DotvvmProperty.Register<bool, ValidationSummary>(c => c.IncludeErrorsFromTarget, false);


        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            var expression = KnockoutHelper.GetValidationTargetExpression(this);
            if (expression != null)
            {
                writer.AddKnockoutDataBind("foreach", $"dotvvm.validation.getValidationErrors({expression}, " +
                    $"{IncludeErrorsFromChildren.ToString().ToLower()}, {IncludeErrorsFromTarget.ToString().ToLower()})");
            }

            base.AddAttributesToRender(writer, context);
        }

        /// <summary>
        /// Renders the contents inside the control begin and end tags.
        /// </summary>
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            // render template
            writer.AddKnockoutDataBind("text", "errorMessage");
            writer.RenderBeginTag("li");<commit_msg>ValidationSummary: fixed JS error when Validation.Enabled=false<commit_after>using System;
using System.Collections.Generic;
using System.Linq;
using DotVVM.Framework.Binding;
using DotVVM.Framework.Runtime;
using DotVVM.Framework.Hosting;

namespace DotVVM.Framework.Controls
{
    /// <summary>
    /// Displays all validation messages from the current Validation.Target.
    /// </summary>
    [ControlMarkupOptions(AllowContent = false)]
    public class ValidationSummary : HtmlGenericControl
    {
        
        /// <summary>
        /// Initializes a new instance of the <see cref="ValidationSummary"/> class.
        /// </summary>
        public ValidationSummary()
        {
            TagName = "ul";
        }


        /// <summary>
        /// Gets or sets whether the errors from child objects in the viewmodel will be displayed too.
        /// </summary>
        [MarkupOptions(AllowBinding = false)]
        public bool IncludeErrorsFromChildren
        {
            get { return (bool) GetValue(IncludeErrorsFromChildrenProperty); }
            set { SetValue(IncludeErrorsFromChildrenProperty, value); }
        }
        public static readonly DotvvmProperty IncludeErrorsFromChildrenProperty
            = DotvvmProperty.Register<bool, ValidationSummary>(c => c.IncludeErrorsFromChildren, false);


        /// <summary>
        /// Gets or sets whether the errors from the <see cref="Validation.TargetProperty"/> object will be displayed too.
        /// </summary>
        [MarkupOptions(AllowBinding = false)]
        public bool IncludeErrorsFromTarget
        {
            get { return (bool) GetValue(IncludeErrorsFromTargetProperty); }
            set { SetValue(IncludeErrorsFromTargetProperty, value); }
        }
        public static readonly DotvvmProperty IncludeErrorsFromTargetProperty
            = DotvvmProperty.Register<bool, ValidationSummary>(c => c.IncludeErrorsFromTarget, false);

        /// <summary>
        /// Adds all attributes that should be added to the control begin tag.
        /// </summary>
        protected override void AddAttributesToRender(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            var expression = KnockoutHelper.GetValidationTargetExpression(this);
            if (expression != null)
            {
                writer.AddKnockoutDataBind("foreach", $"dotvvm.validation.getValidationErrors({expression}, " +
                    $"{IncludeErrorsFromChildren.ToString().ToLower()}, {IncludeErrorsFromTarget.ToString().ToLower()})");
            }
            else
            {
                writer.AddKnockoutDataBind("foreach", $"[]");
            }

            base.AddAttributesToRender(writer, context);
        }

        /// <summary>
        /// Renders the contents inside the control begin and end tags.
        /// </summary>
        protected override void RenderContents(IHtmlWriter writer, IDotvvmRequestContext context)
        {
            // render template
            writer.AddKnockoutDataBind("text", "errorMessage");
            writer.RenderBeginTag("li");
{'fraction_non_alphanumeric': 0.09717607973421927, 'fraction_numerical': 0.0, 'mean_word_length': 2.409399773499434, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6640986', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1417, 'n_words': 364}