public override void Process(TagHelperContext context, TagHelperOutput output) { output.TagMode = TagMode.SelfClosing; output.TagName = null; int i = 0; foreach (var item in Items) { i++; TagBuilder div = new TagBuilder("div"); div.MergeAttribute("class", "form-group"); output.PostContent.AppendHtml(div.RenderStartTag()); string radioId = For.Name + i; output.PostContent.AppendHtml( _generator.GenerateRadioButton( ViewContext, For.ModelExplorer, For.Name, item.Value, (int)For.Model == item.Value, new { Id = radioId })); output.PostContent.AppendHtml( _generator.GenerateLabel( ViewContext, For.ModelExplorer, radioId, item.Text, null)); output.PostContent.AppendHtml(div.RenderEndTag()); } }
public override void Process(TagHelperContext context, TagHelperOutput output) { context.ThrowIfNull(); output.ThrowIfNull(); var modelExplorer = For.ModelExplorer; var kvList = Data.GetKeyValueList(); kvList.ForEach(dic => { var attributes = new Dictionary <string, object> { { "title", dic.Key } }; var inputTagBuilder = _generator.GenerateRadioButton(ViewContext, modelExplorer, For.Name, modelExplorer.Model, dic.Value == (int)(modelExplorer.Model ?? -1), attributes); output.Content.AppendHtml(inputTagBuilder); }); output.TagName = "div"; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Add("class", InputDisplay.GetDisplayName()); }
private void WriteInput(TextWriter writer) { var tagBuilder = htmlGenerator.GenerateRadioButton( ViewContext, For.ModelExplorer, For.Name, value: Value, isChecked: false, htmlAttributes: new { @class = $"radiobuttongroup {Class}" }); tagBuilder.WriteTo(writer, htmlEncoder); }
/// <inheritdoc /> public override void Process(TagHelperContext context, TagHelperOutput output) { output.SuppressOutput(); foreach (var enumItem in For.Metadata.EnumNamesAndValues) { var id = VariantId(enumItem); var name = For.Metadata.EnumGroupedDisplayNamesAndValues.FirstOrDefault(v => v.Value == enumItem.Value).Key.Name; var radio = _generator.GenerateRadioButton(ViewContext, For.ModelExplorer, For.Name, enumItem.Key, false, new { id }); var label = _generator.GenerateLabel(ViewContext, For.ModelExplorer, For.Name, name, new { @for = id }); output.PreElement.AppendHtml(radio); output.PreElement.AppendHtml(label); } }
protected virtual HtmlString GenerateRadioButton(ModelMetadata metadata, string name, object value, bool?isChecked, object htmlAttributes) { var tagBuilder = _htmlGenerator.GenerateRadioButton( ViewContext, metadata, name, value, isChecked, htmlAttributes); if (tagBuilder == null) { return(HtmlString.Empty); } return(tagBuilder.ToHtmlString(TagRenderMode.SelfClosing)); }
/// <inheritdoc /> public override void Process(TagHelperContext context, TagHelperOutput output) { AssertModelIsEnum(); output.SuppressOutput(); foreach (var enumItem in For.Metadata.EnumNamesAndValues) { var id = VariantId(enumItem); var name = For.Metadata.EnumGroupedDisplayNamesAndValues.FirstOrDefault(v => v.Value == enumItem.Value).Key.Name; var radio = _generator.GenerateRadioButton(ViewContext, For.ModelExplorer, For.Metadata.PropertyName, enumItem.Key, false, new { id, @class = "custom-control-input" }); var label = _generator.GenerateLabel(ViewContext, For.ModelExplorer, For.Name, name, new { @for = id, @class = "custom-control-label" }); var container = new TagBuilder("div"); container.Attributes.Add("class", "custom-control custom-radio"); container.InnerHtml.AppendHtml(radio); container.InnerHtml.AppendHtml(label); output.Content.AppendHtml(container); } }
protected virtual IHtmlContent GenerateRadioButton( ModelExplorer modelExplorer, string expression, object value, bool?isChecked, object htmlAttributes) { var tagBuilder = _htmlGenerator.GenerateRadioButton( ViewContext, modelExplorer, expression, value, isChecked, htmlAttributes); if (tagBuilder == null) { return(HtmlString.Empty); } return(tagBuilder); }
public TagBuilder GenerateRadioButton(ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, bool?isChecked, object htmlAttributes) { return(_htmlGenerator.GenerateRadioButton(viewContext, modelExplorer, expression, value, isChecked, htmlAttributes)); }
public override void Process(TagHelperContext context, TagHelperOutput output) { context.ThrowIfNull(); output.ThrowIfNull(); var selectListItems = new List <SelectListItem>(); var kvList = For?.Metadata.EnumGroupedDisplayNamesAndValues; if (kvList != null) { selectListItems = For.Metadata.EnumGroupedDisplayNamesAndValues.Select(a => new SelectListItem { Text = a.Key.Name.ToString(), Value = a.Value.ToString(), Selected = a.Value == ((int)((For.Model) ?? -1)).ToString() }).ToList(); } if (kvList == null && Data != null) { selectListItems = (List <SelectListItem>)Data; } var idStr = TagBuilder.CreateSanitizedId(For.Name, _generator.IdAttributeDotReplacement); var tagBuilder = new StringBuilder(32); selectListItems.ForEach(item => { var attributes = new Dictionary <string, object> { { "title", item.Text }, { "lay-skin", "primary" } }; var inputTagBuilder = _generator.GenerateRadioButton(ViewContext, For.ModelExplorer, For.Name, For.ModelExplorer.Model, item.Value == (string)For.ModelExplorer.Model, attributes); tagBuilder.Append(inputTagBuilder.GetString()); }); var outpuHtml = $@" <label class='layui-form-label'>{Text ?? For.Metadata.DisplayName}</label> <div id='{idStr}_radioGroup' class='layui-input-block'> {tagBuilder} </div>"; output.TagName = "div"; output.TagMode = TagMode.StartTagAndEndTag; output.Attributes.Add("id", $"{idStr}_div"); output.Attributes.Add("class", InputDisplay.GetDisplayName()); output.Content.SetHtmlContent(outpuHtml); if (kvList == null && !Url.IsNullOrEmpty()) { output.PostElement.SetHtmlContent($@"<script type='text/javascript'> $(function () {{ $('#{idStr}_radioGroup').bindRadioData('{Url}','{For.Model}','{For.Name}'); }}); </script>"); } }