private static StringBuilder PanelAlertMode(HtmlHelper helper, BootstrapValidationSummaryOptions options) { StringBuilder builder = new StringBuilder(); //add the main panel builder.AppendFormat("<div class=\"{0} {1}\">", options.PanelDisplaySettings.ContainerClass, options.PanelDisplaySettings.ContainerEmphasisClass); //add the header builder.AppendFormat("<div class=\"{0}\">", options.PanelDisplaySettings.HeadingClass); builder.AppendFormat("<h4 class=\"{0}\">{1}</h4>", options.PanelDisplaySettings.TitleClass, options.Title); //close the header builder.Append("</div>"); //open the panel body builder.AppendFormat("<div class=\"{0}\">", options.PanelDisplaySettings.BodyClass); builder.Append(AddIntroductionText(options.IntroductionBlock, options.PanelDisplaySettings)); builder.Append(AddModelErrors(helper, options.ShowModelErrors, options.PanelDisplaySettings)); //close the panel body builder.Append("</div>"); //close the panel builder.Append("</div>"); return(builder); }
private static StringBuilder ModalAlertMode(HtmlHelper helper, BootstrapValidationSummaryOptions options) { StringBuilder builder = new StringBuilder(); //open up the modal window builder.AppendFormat("<div class=\"{0} {1} \" id=\"SummaryErrors\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"SummaryErrorLabel\" aria-hidden=\"true\">", options.ModalDisplaySettings.ContainerClass, options.ModalDisplaySettings.ContainerEmphasisClass); //add the dialog builder.AppendFormat("<div class=\"{0}\">", options.ModalDisplaySettings.ModalDialogClass); //add the content builder.AppendFormat("<div class=\"{0}\">", options.ModalDisplaySettings.ModalDialogContentClass); //add the header builder.AppendFormat("<div class=\"{0}\">", options.ModalDisplaySettings.HeadingClass); //add button to close the modal builder.AppendFormat("<button type=\"button\" class=\"{0}\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>", options.ModalDisplaySettings.CloseButtonClass); builder.AppendFormat("<h4 class=\"{0}\" id=\"SummaryErrorLabel\">{1}</h4>", options.ModalDisplaySettings.TitleClass, options.Title); //close the header builder.Append("</div>"); //open the body builder.AppendFormat("<div class=\"{0}\">", options.ModalDisplaySettings.BodyClass); //add introduction text builder.Append(AddIntroductionText(options.IntroductionBlock, options.ModalDisplaySettings).ToString()); //add the model errors builder.Append(AddModelErrors(helper, options.ShowModelErrors, options.ModalDisplaySettings)); //close the body builder.Append("</div>"); //close the content builder.Append("</div>"); //close the dialog builder.Append("</div>"); //close the modal window builder.Append("</div>"); //add javascript to fire up the modal when the document has finished loading. builder.Append("<script>$(document).ready(function(){ $(\"#SummaryErrors\").modal(\"show\");}); </script>"); return(builder); }
private static StringBuilder AlertMode(this HtmlHelper helper, bool closable, BootstrapValidationSummaryOptions options) { //this is the standard alert mode box. StringBuilder builder = new StringBuilder(); if (closable) { builder.AppendFormat("<div class=\"{0} {1} {2}\">", options.AlertDisplaySettings.ContainerClass, options.AlertDisplaySettings.ContainerEmphasisClass, options.AlertDisplaySettings.ContainerDismissibleClass); builder.AppendFormat("<button type=\"{0}\" class=\"{1}\" data-dismiss=\"{2}\" aria-hidden=\"{3}\">×</button>", "button", options.AlertDisplaySettings.CloseButtonClass, "alert", "true"); } else { builder.AppendFormat("<div class=\"{0} {1} \">", "alert", "alert-danger"); } builder.Append(AddIntroductionText(options.IntroductionBlock, options.AlertDisplaySettings).ToString()); //add the model errors here. builder.Append(AddModelErrors(helper, options.ShowModelErrors, options.AlertDisplaySettings).ToString()); builder.Append("</div>"); return(builder); }
public static MvcHtmlString BootStrapValidationSummary(this HtmlHelper helper, BootstrapValidationSummaryOptions options = null) { StringBuilder stringBuilder = new StringBuilder(); if (options == null) { options = new BootstrapValidationSummaryOptions(); } // first lets check to see if we have any errors in the system. if (helper.ViewData.ModelState.IsValid) { //we have a valid model lets not do anything. return(new MvcHtmlString(string.Empty)); } switch (options.DisplayMode) { case ErrorMode.Alert: { stringBuilder = AlertMode(helper, false, options); break; } case ErrorMode.ClosableAlert: { stringBuilder = AlertMode(helper, true, options); break; } case ErrorMode.Modal: { stringBuilder = ModalAlertMode(helper, options); break; } case ErrorMode.Panel: { stringBuilder = PanelAlertMode(helper, options); break; } default: { //default mode will be standard alert mode. stringBuilder = AlertMode(helper, false, options); break; } } MvcHtmlString returnString = new MvcHtmlString(stringBuilder.ToString()); return(returnString); }
public static MvcHtmlString BootStrapValidationSummary(this HtmlHelper helper, BootstrapValidationSummaryOptions options = null) { ///This is the full script for altering the labels on required fields. ///I have tweaked from original version to handle checkbox and text box validation. string requiredDecoratingScript = "<script>" + "$(this).ready(function () {" + "$('[data-val-required]').each(function () {" + "var label = $(\"label[for='\" + $(this).attr('id') + \"']\");" + "var isCheckbox = $(this).is(':checkbox');" + "var isTextbox = $(this).is(':text');" + "var isPassword = $(this).is(':password');" + "var isValidTextValue = true;" + "if(isTextbox || isPassword)" + "{" + "isValidTextValue = $(this).val() !== '';" + "}" + "label.removeClass(\"text-success\");" + "label.removeClass(\"text-danger\");" + "if ((" + ((helper.ViewData.ModelState.IsValid) ? "true" : "false") + "|$(this).hasClass(\"input-validation-error\") | !isValidTextValue) " + "&& !isCheckbox" + ") {" + "label.addClass(\"text-danger\");" + "}" + "else " + "{" + "if(!isCheckbox){" + "label.addClass(\"text-success\");" + "}" + "}" + "});" + "}); " + "</script>"; string requiredbox = "<div class=\"well well-sm\"><p>All labels like <strong class=\"text-danger\">this</strong> are required fields.</p>" + "<p>All labels like <strong class=\"text-success\">this</strong> are valid required fields.</p></div>"; StringBuilder stringBuilder = new StringBuilder(); if (options == null) { options = new BootstrapValidationSummaryOptions(); } if (!options.EnableRequiredFieldHelp) { requiredbox = string.Empty; } if (!options.EnableRequiredFieldIndicators) { requiredDecoratingScript = string.Empty; } // first lets check to see if we have any errors in the system. if (helper.ViewData.ModelState.IsValid) { //we have a valid model lets not do anything. return(new MvcHtmlString(requiredbox + requiredDecoratingScript)); } //To ensure compatability with JQuery Validate We need to wrap this up into a new validation div that will be hidden by default but will display once the system is launched //Need to see how I can do this is a nicer way without having to rewrite the entire helper. string unObtrusiveStringOpen = string.Format("<div class=\"{0}\" data-valmsg-summary=\"true\">", (helper.ViewData.ModelState.IsValid) ? "validation-summary-valid" : "validation-summary-errors"); string unObtrusiveStringEnd = string.Format("</div>"); switch (options.DisplayMode) { case ErrorMode.Alert: { stringBuilder = AlertMode(helper, false, options); break; } case ErrorMode.ClosableAlert: { stringBuilder = AlertMode(helper, true, options); break; } case ErrorMode.Modal: { stringBuilder = ModalAlertMode(helper, options); break; } case ErrorMode.Panel: { stringBuilder = PanelAlertMode(helper, options); break; } case ErrorMode.CollapsePanel: { stringBuilder = CollapsePanelAlertMode(helper, options); break; } default: { //default mode will be standard alert mode. stringBuilder = AlertMode(helper, false, options); break; } } // MvcHtmlString returnString = new MvcHtmlString(requiredbox + unObtrusiveStringOpen + stringBuilder.ToString() + unObtrusiveStringEnd + requiredDecoratingScript); MvcHtmlString returnString = new MvcHtmlString(requiredbox + stringBuilder.ToString() + requiredDecoratingScript); return(returnString); }
private static StringBuilder CollapsePanelAlertMode(HtmlHelper helper, BootstrapValidationSummaryOptions options) { StringBuilder builder = new StringBuilder(); //add the main panel builder.AppendFormat("<div class=\"{0} {1}\" id=\"{2}\">", options.PanelDisplaySettings.ContainerClass, options.PanelDisplaySettings.ContainerEmphasisClass, "SummaryCollapsePanel"); //add the header builder.AppendFormat("<div class=\"{0}\">", options.PanelDisplaySettings.HeadingClass); builder.AppendFormat("<div class=\"{0}\">", options.PanelDisplaySettings.TitleClass); builder.AppendFormat("<a href=\"#{0}\" data-toggle=\"collapse\" data-parent=\"#{1}\">", "SummaryErrorBody", "SummaryCollapsePanel"); builder.AppendFormat("<h4>{0} <span id=\"Errorheader-icon\" class=\"pull-right glyphicon glyphicon-plus-sign\"></span> </h4>", options.Title); builder.AppendFormat("</a>"); //close the header builder.Append("</div>"); builder.Append("</div>"); //open the panel body builder.AppendFormat("<div class=\"{0}\" id=\"{1}\">", "panel-collapse collapse in", "SummaryErrorBody"); builder.Append(AddIntroductionText(options.IntroductionBlock, options.PanelDisplaySettings)); builder.Append(AddModelErrors(helper, options.ShowModelErrors, options.PanelDisplaySettings)); //close the panel body builder.Append("</div>"); //close the panel builder.Append("</div>"); //now build in the collapse script builder.AppendFormat("<script>"); builder.Append("$(document).ready(function () {" + " $(\"#SummaryCollapsePanel\").click(function () { " + "var control = $(\"#Errorheader-icon\");" + "if (control.hasClass(\"glyphicon-plus-sign\")) {" + "control.removeClass(\"glyphicon-plus-sign\");" + "control.removeClass(\"glyphicon\");" + "control.addClass(\"glyphicon\");" + "control.addClass(\"glyphicon-minus-sign\");" + " } else {" + "control.removeClass(\"glyphicon-minus-sign\");" + "control.removeClass(\"glyphicon\");" + "control.addClass(\"glyphicon\");" + "control.addClass(\"glyphicon-plus-sign\");" + "} " + " });" + "});" ); //close the script tag builder.AppendFormat("</script>"); return(builder); }
private static StringBuilder AlertMode(this HtmlHelper helper, bool closable, BootstrapValidationSummaryOptions options) { //this is the standard alert mode box. StringBuilder builder = new StringBuilder(); if (closable) { builder.AppendFormat("<div class=\"{0} {1} {2}\">", options.AlertDisplaySettings.ContainerClass, options.AlertDisplaySettings.ContainerEmphasisClass, options.AlertDisplaySettings.ContainerDismissibleClass); builder.AppendFormat("<button type=\"{0}\" class=\"{1}\" data-dismiss=\"{2}\" aria-hidden=\"{3}\">×</button>", "button", options.AlertDisplaySettings.CloseButtonClass, "alert", "true"); } else { builder.AppendFormat("<div class=\"{0} {1} \">", options.AlertDisplaySettings.ContainerClass, options.AlertDisplaySettings.ContainerEmphasisClass); } builder.AppendFormat("<h4>{0}</h4>", options.Title); builder.Append(AddIntroductionText(options.IntroductionBlock, options.AlertDisplaySettings).ToString()); //add the model errors here. builder.Append(AddModelErrors(helper, options.ShowModelErrors, options.AlertDisplaySettings).ToString()); builder.Append("</div>"); return builder; }
private static StringBuilder ModalAlertMode(HtmlHelper helper, BootstrapValidationSummaryOptions options) { StringBuilder builder = new StringBuilder(); //open up the modal window builder.AppendFormat("<div class=\"{0} {1} \" id=\"SummaryErrors\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"SummaryErrorLabel\" aria-hidden=\"true\">", options.ModalDisplaySettings.ContainerClass, options.ModalDisplaySettings.ContainerEmphasisClass); //add the dialog builder.AppendFormat("<div class=\"{0}\">", options.ModalDisplaySettings.ModalDialogClass); //add the content builder.AppendFormat("<div class=\"{0}\">", options.ModalDisplaySettings.ModalDialogContentClass); //add the header builder.AppendFormat("<div class=\"{0}\">", options.ModalDisplaySettings.HeadingClass); //add button to close the modal builder.AppendFormat("<button type=\"button\" class=\"{0}\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>", options.ModalDisplaySettings.CloseButtonClass); builder.AppendFormat("<h4 class=\"{0}\" id=\"SummaryErrorLabel\">{1}</h4>", options.ModalDisplaySettings.TitleClass, options.Title); //close the header builder.Append("</div>"); //open the body builder.AppendFormat("<div class=\"{0}\">", options.ModalDisplaySettings.BodyClass); //add introduction text builder.Append(AddIntroductionText(options.IntroductionBlock, options.ModalDisplaySettings).ToString()); //add the model errors builder.Append(AddModelErrors(helper, options.ShowModelErrors, options.ModalDisplaySettings)); //close the body builder.Append("</div>"); //close the content builder.Append("</div>"); //close the dialog builder.Append("</div>"); //close the modal window builder.Append("</div>"); //add javascript to fire up the modal when the document has finished loading. builder.Append("<script>$(document).ready(function(){ $(\"#SummaryErrors\").modal(\"show\");}); </script>"); return builder; }
private static StringBuilder PanelAlertMode(HtmlHelper helper, BootstrapValidationSummaryOptions options) { StringBuilder builder = new StringBuilder(); //add the main panel builder.AppendFormat("<div class=\"{0} {1}\">", options.PanelDisplaySettings.ContainerClass, options.PanelDisplaySettings.ContainerEmphasisClass); //add the header builder.AppendFormat("<div class=\"{0}\">", options.PanelDisplaySettings.HeadingClass); builder.AppendFormat("<h4 class=\"{0}\">{1}</h4>", options.PanelDisplaySettings.TitleClass, options.Title); //close the header builder.Append("</div>"); //open the panel body builder.AppendFormat("<div class=\"{0}\">", options.PanelDisplaySettings.BodyClass); builder.Append(AddIntroductionText(options.IntroductionBlock, options.PanelDisplaySettings)); builder.Append(AddModelErrors(helper, options.ShowModelErrors, options.PanelDisplaySettings)); //close the panel body builder.Append("</div>"); //close the panel builder.Append("</div>"); return builder; }
private static StringBuilder CollapsePanelAlertMode(HtmlHelper helper, BootstrapValidationSummaryOptions options) { StringBuilder builder = new StringBuilder(); //add the main panel builder.AppendFormat("<div class=\"{0} {1}\" id=\"{2}\">", options.PanelDisplaySettings.ContainerClass, options.PanelDisplaySettings.ContainerEmphasisClass, "SummaryCollapsePanel"); //add the header builder.AppendFormat("<div class=\"{0}\">", options.PanelDisplaySettings.HeadingClass); builder.AppendFormat("<div class=\"{0}\">", options.PanelDisplaySettings.TitleClass); builder.AppendFormat("<a href=\"#{0}\" data-toggle=\"collapse\" data-parent=\"#{1}\">", "SummaryErrorBody", "SummaryCollapsePanel"); builder.AppendFormat("<h4>{0} <span id=\"Errorheader-icon\" class=\"pull-right glyphicon glyphicon-plus-sign\"></span> </h4>", options.Title); builder.AppendFormat("</a>"); //close the header builder.Append("</div>"); builder.Append("</div>"); //open the panel body builder.AppendFormat("<div class=\"{0}\" id=\"{1}\">", "panel-collapse collapse in", "SummaryErrorBody"); builder.Append(AddIntroductionText(options.IntroductionBlock, options.PanelDisplaySettings)); builder.Append(AddModelErrors(helper, options.ShowModelErrors, options.PanelDisplaySettings)); //close the panel body builder.Append("</div>"); //close the panel builder.Append("</div>"); //now build in the collapse script builder.AppendFormat("<script>"); builder.Append("$(document).ready(function () {" + " $(\"#SummaryCollapsePanel\").click(function () { " + "var control = $(\"#Errorheader-icon\");" + "if (control.hasClass(\"glyphicon-plus-sign\")) {" + "control.removeClass(\"glyphicon-plus-sign\");" + "control.removeClass(\"glyphicon\");" + "control.addClass(\"glyphicon\");" + "control.addClass(\"glyphicon-minus-sign\");" + " } else {" + "control.removeClass(\"glyphicon-minus-sign\");" + "control.removeClass(\"glyphicon\");" + "control.addClass(\"glyphicon\");" + "control.addClass(\"glyphicon-plus-sign\");" + "} " + " });" + "});" ); //close the script tag builder.AppendFormat("</script>"); return builder; }
public static MvcHtmlString BootStrapValidationSummary(this HtmlHelper helper, BootstrapValidationSummaryOptions options = null) { ///This is the full script for altering the labels on required fields. ///I have tweaked from original version to handle checkbox and text box validation. string requiredDecoratingScript = "<script>" + "$(this).ready(function () {" + "$('[data-val-required]').each(function () {" + "var label = $(\"label[for='\" + $(this).attr('id') + \"']\");" + "var isCheckbox = $(this).is(':checkbox');" + "var isTextbox = $(this).is(':text');" + "var isPassword = $(this).is(':password');" + "var isValidTextValue = true;" + "if(isTextbox || isPassword)" + "{" + "isValidTextValue = $(this).val() !== '';" + "}" + "label.removeClass(\"text-success\");" + "label.removeClass(\"text-danger\");" + "if ((" + ((helper.ViewData.ModelState.IsValid) ? "true" : "false") + "|$(this).hasClass(\"input-validation-error\") | !isValidTextValue) " + "&& !isCheckbox" + ") {" + "label.addClass(\"text-danger\");" + "}" + "else " + "{" + "if(!isCheckbox){" + "label.addClass(\"text-success\");" + "}" + "}" + "});" + "}); " + "</script>"; string requiredbox = "<div class=\"well well-sm\"><p>All labels like <strong class=\"text-danger\">this</strong> are required fields.</p>" + "<p>All labels like <strong class=\"text-success\">this</strong> are valid required fields.</p></div>"; StringBuilder stringBuilder = new StringBuilder(); if (options == null) { options = new BootstrapValidationSummaryOptions(); } if (!options.EnableRequiredFieldHelp) { requiredbox = string.Empty; } if (!options.EnableRequiredFieldIndicators) { requiredDecoratingScript = string.Empty; } // first lets check to see if we have any errors in the system. if (helper.ViewData.ModelState.IsValid) { //we have a valid model lets not do anything. return new MvcHtmlString(requiredbox + requiredDecoratingScript); } //To ensure compatability with JQuery Validate We need to wrap this up into a new validation div that will be hidden by default but will display once the system is launched //Need to see how I can do this is a nicer way without having to rewrite the entire helper. string unObtrusiveStringOpen = string.Format("<div class=\"{0}\" data-valmsg-summary=\"true\">", (helper.ViewData.ModelState.IsValid) ? "validation-summary-valid" : "validation-summary-errors"); string unObtrusiveStringEnd = string.Format("</div>"); switch (options.DisplayMode) { case ErrorMode.Alert: { stringBuilder = AlertMode(helper, false, options); break; } case ErrorMode.ClosableAlert: { stringBuilder = AlertMode(helper, true, options); break; } case ErrorMode.Modal: { stringBuilder = ModalAlertMode(helper, options); break; } case ErrorMode.Panel: { stringBuilder = PanelAlertMode(helper, options); break; } case ErrorMode.CollapsePanel: { stringBuilder = CollapsePanelAlertMode(helper, options); break; } default: { //default mode will be standard alert mode. stringBuilder = AlertMode(helper, false, options); break; } } // MvcHtmlString returnString = new MvcHtmlString(requiredbox + unObtrusiveStringOpen + stringBuilder.ToString() + unObtrusiveStringEnd + requiredDecoratingScript); MvcHtmlString returnString = new MvcHtmlString(requiredbox + stringBuilder.ToString() + requiredDecoratingScript); return returnString; }