public virtual HtmlDocument BuildView(IUrlRegistry urls, IOutputWriter writer, LoginRequest request) { // TODO -- Revisit all of this when we get HTML conventions everywhere var view = new HtmlDocument(); var form = new FormTag(urls.UrlFor <LoginRequest>("POST")); form.Append(new HtmlTag("legend").Text(LoginKeys.Login)); if (request.Message.IsNotEmpty()) { form.Append(new HtmlTag("p").Text(request.Message).Style("color", "red")); } form.Append(new TextboxTag("UserName", request.UserName)); form.Append(new TextboxTag("Password", request.Password)); form.Append(new CheckboxTag(request.RememberMe).Name("RememberMe")); form.Append(new DivTag().Text(request.Message).Id("login-message")); form.Append(new HiddenTag().Name("Url").Attr("value", request.Url)); form.Append(new HtmlTag("input").Attr("type", "submit").Attr("value", LoginKeys.Login).Id("login-submit")); view.Add(form); return(view); }
public static FormTag WithValidationSummary <T>(this FormTag form) { form.Id(typeof(T).Name); var summary = new HtmlTag("div") .AddClasses("alert", "alert-error", "validation-container") .Append(new HtmlTag("p").Text(HelloValidationKeys.Summary)) .Append(new HtmlTag("ul").AddClass("validation-summary")) .Style("display", "none"); form.Append(summary); return(form); }
public static FormTag ValidationSummary <T>(this FormTag form) { form.Id(typeof(T).Name); var summary = new HtmlTag("div") .AddClasses("alert", "alert-error", "validation-container") .Append(new HtmlTag("p").Text("There are errors with the information you provided.")) .Append(new HtmlTag("ul").AddClass("validation-summary")) .Style("display", "none"); form.Append(summary); return(form); }
static HtmlTag GenerateForm <TModel> (TModel model, FormType formType, FormTag formTag) { foreach (var prop in model.GetType().GetProperties()) { //var value = prop.GetValue (model, null); var visibility = (ScaffoldVisibilityType)model.GetAttributeValue(prop, typeof(ScaffoldVisibilityAttribute), formType.ToString()); if (visibility == ScaffoldVisibilityType.None) { continue; } if (visibility == ScaffoldVisibilityType.Show) { var type = prop.PropertyType; if (type == typeof(string)) { formTag.Append(GenerateInputText <TModel> (model, prop)); } else if (type == typeof(bool)) { formTag.Append(GenerateInputCheck <TModel> (model, prop)); } else if (typeof(IEnumerable).IsAssignableFrom(type)) { formTag.Append(GenerateSelect <TModel> (model, prop)); } else if (type.IsEnum) { formTag.Append(GenerateSelect <TModel> (model, prop)); } else if (typeof(DateTime).IsAssignableFrom(type) || typeof(DateTimeOffset).IsAssignableFrom(type)) { formTag.Append(GenerateCalendar <TModel> (model, prop)); } } else { formTag.Append(GenerateInputHidden <TModel> (model, prop)); } } if (formTag.Children.Count == 0) { return(null); } return(formTag); }
protected override void beforeEach() { theGraph = BehaviorGraph.BuildFrom(x => x.Actions.IncludeType <ValidationSummaryTargetEndpoint>()); Services.Inject <IChainResolver>(new ChainResolutionCache(theGraph)); theRequest = new FormRequest(new ChainSearch { Type = typeof(ValidationSummaryTarget) }, new ValidationSummaryTarget()); theRequest.Attach(new StructureMapServiceLocator(Services.Container)); ValidationPolicy.ApplyValidation(theRequest.Chain.FirstCall(), new ValidationSettings()); theRequest.Chain.ValidationNode().Clear(); theRequest.Chain.ValidationNode().RegisterStrategy(RenderingStrategies.Summary); var theForm = new FormTag("test"); theForm.Append(new HtmlTag("input").Attr("type", "text").Attr("name", "Name")); theRequest.ReplaceTag(theForm); MockFor <IPartialInvoker>().Stub(x => x.Invoke <ValidationSummary>()).Return(theValidationSummary.ToCompletionTask()); }
public static HtmlString AdminForm(DocumentNode Model, string adminUrl, string divClassName = "") { var div = new HtmlTag("div"); if (divClassName != "") { div.AddClass(divClassName); } var form = new FormTag().Method("post").Action("#"); form.Append(HtmlBuilder.HtmlTagLabelInput("Name (header)", "name", Model.Name)); form.Append(new HtmlTag("input").Attr("type", "submit").Attr("name", "update").Attr("value", "Update")); form.Append(HtmlBuilder.HtmlTagLabelCheckbox("Hide header", "hideHeader", Model.HideHeader)); form.Append(HtmlBuilder.HtmlTagLabelTextArea("Body text", "body", Model.Body)); form.Append(HtmlBuilder.HtmlTagLabelTextArea("Extra content 1", "extraContent1", Model.ExtraContent1, 5)); //form.Append(HtmlBuilder.HtmlTagLabelTextArea("Extra content 2", "extraContent2", Model.ExtraContent2, 5)); //form.Append(HtmlBuilder.HtmlTagLabelTextArea("Extra content 3", "extraContent3", Model.ExtraContent3, 3)); form.Append(HtmlBuilder.HtmlTagLabelInput("Author", "author", Model.Author)); form.Append(HtmlBuilder.HtmlTagLabelInput("ViewPath", "viewPath", Model.ViewPath)); form.Append(HtmlBuilder.HtmlTagLabelCheckbox("Hidden", "isHidden", Model.IsHidden)); form.Append(HtmlBuilder.HtmlTagLabelCheckbox("Deleted", "isDeleted", Model.IsDeleted)); form.Append(new HtmlTag("input").Attr("type", "submit").Attr("name", "update").Attr("value", "Update")); if (!String.IsNullOrEmpty(Model.Url)) { form.Append(new HtmlTag("p").Append(new HtmlTag("a").Attr("href", Model.Url).Text("View page"))); } div.Append(form); return(new HtmlString(div.ToHtmlString())); }