public void Execute(IMemberElement element)
 {
     var helper = new MemberBehaviorHelper<RequiredAttribute>();
     var attribute = helper.GetAttribute(element);
     if (attribute != null)
     {
         element.SetAttr("class", "req");
     }
 }
示例#2
0
        public void Execute(IMemberElement element)
        {
            var attribute = new MemberBehaviorHelper<StringLengthAttribute>().GetAttribute(element);

            if(attribute != null && element is ISupportsMaxLength)
            {
                element.SetAttr(HtmlAttribute.MaxLength, attribute.MaximumLength);
            }
        }
示例#3
0
        public void Execute(IMemberElement element)
        {
            var helper    = new MemberBehaviorHelper <RequiredAttribute>();
            var attribute = helper.GetAttribute(element);

            if (attribute != null)
            {
                element.SetAttr("class", "req");
            }
        }
        public void Execute(TextBox textBox)
        {
            var helper    = new MemberBehaviorHelper <StringLengthAttribute>();
            var attribute = helper.GetAttribute(textBox);

            if (attribute == null)
            {
                return;
            }

            textBox.MaxLength(attribute.MaximumLength);
        }
示例#5
0
        public void Execute(IMemberElement behavee)
        {
            var helper    = new MemberBehaviorHelper <RequiredAttribute>();
            var attribute = helper.GetAttribute(behavee);

            if (attribute != null)
            {
                var data = new Dictionary <string, bool> {
                    { "required", true }
                };
                BehaviorHelper.AddDataToClass(behavee, data);
            }
        }
示例#6
0
        public void text_box_for_member_with_maxlength_attibute_sets_maxlength()
        {
            Expression <Func <FakeModel, object> > expression = x => x.Title;
            var behaviors = new List <IBehaviorMarker> {
                new CustomMaxLengthBehavior()
            };
            var expectedLength = new MemberBehaviorHelper <RangeAttribute>()
                                 .GetAttribute(expression.GetMemberExpression()).Maximum;

            var html = new TextBox(expression.GetNameFor(), expression.GetMemberExpression(), behaviors).ToString();

            var element = html.ShouldHaveHtmlNode("Title");

            element.ShouldHaveAttribute(HtmlAttribute.MaxLength).WithValue(expectedLength.ToString());
        }
        public void Execute(IMemberElement element)
        {
            var helper = new MemberBehaviorHelper<RangeAttribute>();
            var attribute = helper.GetAttribute(element);

            if (attribute == null)
            {
                return;
            }

            if (element is ISupportsMaxLength)
            {
                element.SetAttr(HtmlAttribute.MaxLength, attribute.Maximum);
            }
        }
示例#8
0
        public void Execute(IMemberElement element)
        {
            var helper    = new MemberBehaviorHelper <RangeAttribute>();
            var attribute = helper.GetAttribute(element);

            if (attribute == null)
            {
                return;
            }

            if (element is ISupportsMaxLength)
            {
                element.SetAttr(HtmlAttribute.MaxLength, attribute.Maximum);
            }
        }
示例#9
0
        /// <summary>
        /// This behavior affects elements bound to model properties having the Range attribute.  It adds Json data
        /// to the element's attribute incdicating the maximum and minimum values for the field.
        /// </summary>
        public void Execute(IMemberElement behavee)
        {
            var memberBehaviorHelper = new MemberBehaviorHelper <RangeAttribute>();
            var attribute            = memberBehaviorHelper.GetAttribute(behavee);

            if (attribute != null)
            {
                var data = new Dictionary <string, object>
                {
                    { "maximum", attribute.Maximum },
                    { "minimum", attribute.Minimum }
                };
                BehaviorHelper.AddDataToClass(behavee, data);
            }
        }
示例#10
0
        public void text_box_for_member_with_maxlength_attibute_sets_maxlength()
        {
            Expression<Func<FakeModel, object>> expression = x => x.Title;
            var behaviors = new List<IBehaviorMarker> { new CustomMaxLengthBehavior() };
            var expectedLength = new MemberBehaviorHelper<RangeAttribute>()
                .GetAttribute(expression.GetMemberExpression()).Maximum;

            var html = new TextBox(expression.GetNameFor(), expression.GetMemberExpression(), behaviors).ToString();

            var element = html.ShouldHaveHtmlNode("Title");
            element.ShouldHaveAttribute(HtmlAttribute.MaxLength).WithValue(expectedLength.ToString());
        }