Added validation to input group

pull/272/head
yekalkan 7 years ago
parent 6e57405a90
commit b95ddd50c6

@ -42,16 +42,33 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
var inputHtml = RenderTagHelperOutput(inputTag, _encoder); var inputHtml = RenderTagHelperOutput(inputTag, _encoder);
var label = GetLabelAsHtml(inputTag, isCheckbox); var label = GetLabelAsHtml(inputTag, isCheckbox);
return GetContent(label, inputHtml, isCheckbox); var validation = isCheckbox ? "" : GetValidationAsHtml(context);
return GetContent(label, inputHtml, validation, isCheckbox);
}
protected virtual string GetValidationAsHtml(TagHelperContext context)
{
var validationMessageTagHelper = new ValidationMessageTagHelper(_generator)
{
For = TagHelper.AspFor,
ViewContext = TagHelper.ViewContext
};
var attributeList = new TagHelperAttributeList { { "class", "form-control" } };
return RenderTagHelper(attributeList, context, validationMessageTagHelper, _encoder, "span", TagMode.StartTagAndEndTag);
} }
protected virtual string GetContent(string label, string inputHtml, bool isCheckbox) protected virtual string GetContent(string label, string inputHtml, string validation, bool isCheckbox)
{ {
var innerContent = isCheckbox ? var innerContent = isCheckbox ?
inputHtml + Environment.NewLine + label : inputHtml + Environment.NewLine + label :
label + Environment.NewLine + inputHtml; label + Environment.NewLine + inputHtml;
return "<div class=\"" + (isCheckbox ? "form-check" : "form-group") + "\">" + Environment.NewLine + innerContent + Environment.NewLine + "</div>"; return "<div class=\"" + (isCheckbox ? "form-check" : "form-group") + "\">" +
Environment.NewLine + innerContent + Environment.NewLine +
Environment.NewLine + validation + Environment.NewLine +
"</div>";
} }
protected virtual TagHelperOutput GetInputTag(TagHelperContext context, out bool isCheckbox) protected virtual TagHelperOutput GetInputTag(TagHelperContext context, out bool isCheckbox)

@ -66,7 +66,6 @@ namespace Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form
return inputTagHelperOutput; return inputTagHelperOutput;
} }
protected virtual string GetLabelAsHtml(TagHelperOutput selectTag) protected virtual string GetLabelAsHtml(TagHelperOutput selectTag)
{ {
if (string.IsNullOrEmpty(TagHelper.Label) && string.IsNullOrEmpty(TagHelper.AspFor.Metadata.DisplayName)) if (string.IsNullOrEmpty(TagHelper.Label) && string.IsNullOrEmpty(TagHelper.AspFor.Metadata.DisplayName))

Loading…
Cancel
Save