public static HtmlTag InputBlock <T>(this IHtmlHelper <T> helper, Expression <Func <T, object> > expression, string placeholderText = null, string helpTooltipText = null, Action <HtmlTag> inputModifier = null, string customLabelText = null) where T : class
        {
            Preconditions.ThrowIfNull(helper, nameof(helper));
            Preconditions.ThrowIfNull(expression, nameof(expression));

            var label = helper.Label(expression);

            if (customLabelText != null)
            {
                label.Text(customLabelText);
            }
            label = label.WrapWith(new DivTag().AddClasses("col-xs-4", "text-right"));

            var input = helper.Input(expression);

            if (!string.IsNullOrEmpty(placeholderText))
            {
                input.AddPlaceholder(placeholderText);
            }
            inputModifier?.Invoke(input);

            var isCheckbox = expression?.ToAccessor()?.PropertyType == typeof(bool);

            input = input.WrapWith(new DivTag().AddClasses("col-xs-6", isCheckbox ? "text-left" : "text-center"));


            var helpTooltip = helper.ToolTip(helpTooltipText);

            helpTooltip = helpTooltip.AddClasses("col-xs-2");

            return(FormBlock(label, input, helpTooltip));
        }
Exemplo n.º 2
0
        public static HtmlTag InputTextAreaBlock <T>(this IHtmlHelper <T> helper, Expression <Func <T, object> > expression, string value = null, string placeholderText = null, string helpText = null, Action <HtmlTag> inputModifier = null, string customLabelText = null) where T : class
        {
            Preconditions.ThrowIfNull(helper, nameof(helper));
            Preconditions.ThrowIfNull(expression, nameof(expression));

            var label = helper.Label(expression);

            if (customLabelText != null)
            {
                label.Text(customLabelText);
            }
            label = label.WrapWith(new DivTag().AddClasses("col-xs-4", "text-right"));

            var expressionPropertyName = Property.From(expression).Name;

            var textAreaInput = new HtmlTag("textarea")
                                .Id(expressionPropertyName)
                                .Name(expressionPropertyName)
                                .AddClass("form-control");

            if (!string.IsNullOrEmpty(value))
            {
                textAreaInput.AppendText(value);
            }

            if (!string.IsNullOrEmpty(placeholderText))
            {
                textAreaInput.AddPlaceholder(placeholderText);
            }
            inputModifier?.Invoke(textAreaInput);

            textAreaInput = textAreaInput.WrapWith(new DivTag().AddClasses("col-xs-6", "text-left"));
            textAreaInput.Append(new HtmlTag("small").AppendText(helpText).AddClass("text-muted"));

            return(FormBlock(label, textAreaInput, HtmlTag.Empty()));
        }