/// <summary> /// Returns HTML for an <input> HTML element. /// </summary> /// <param name="inputType">The type of input to produce</param> /// <param name="fieldConfiguration">The field configuration to use for attributes and format string</param> /// <returns>The HTML of the input element</returns> protected IHtmlContent GetInputHtml(TextInputType inputType, IReadonlyFieldConfiguration fieldConfiguration) { if (inputType == TextInputType.Password) { return(FieldGenerator.HtmlHelper.PasswordFor(FieldGenerator.FieldProperty, fieldConfiguration.HtmlAttributes)); } var attrs = new HtmlAttributes(fieldConfiguration.HtmlAttributes); if (!attrs.Attributes.ContainsKey("type")) { attrs = attrs.Attr(type => inputType.ToString().ToLower()); } IHtmlContent htmlContent; if (!string.IsNullOrEmpty(fieldConfiguration.FormatString)) { htmlContent = FieldGenerator.HtmlHelper.TextBoxFor( FieldGenerator.FieldProperty, fieldConfiguration.FormatString, attrs.ToDictionary() ); } else { htmlContent = FieldGenerator.HtmlHelper.TextBoxFor( FieldGenerator.FieldProperty, attrs.ToDictionary() ); } return(htmlContent); }
public void Replace_attributes_with_empty_string_when_null_value_added_using_key_value([Values(1, 2)] int setMethod) { var h = new HtmlAttributes(name => "Old"); switch (setMethod) { case 1: h.Attr(name => null); break; case 2: h.Attr("name", null); break; } Assert.That(h.ToHtmlString(), Is.EqualTo(" name=\"\"")); }
public void Replace_existing_attribute_using_a_lambda() { var h = new HtmlAttributes(href => "http://url/"); h.Attr(href => "newhref"); Assert.That(h.ToHtmlString(), Is.EqualTo(" href=\"newhref\"")); }
public void Add_new_attribute_using_a_lambda() { var h = new HtmlAttributes(href => "http://url/"); h.Attr(data_value => "val"); Assert.That(h.ToHtmlString(), Is.EqualTo(" data-value=\"val\" href=\"http://url/\"")); }
public void Ensure_merged_attributes_are_case_sensitive([Values(1, 2, 3)] int setMethod) { var h = new HtmlAttributes(name => "Old"); switch (setMethod) { case 1: h.Attr(Name => "honey-badger"); break; case 2: h.Attr("Name", "honey-badger"); break; case 3: h.Attrs(new { Name = "honey-badger" }); break; } Assert.That(h.ToHtmlString(), Is.EqualTo(" name=\"honey-badger\"")); }
protected Nancy.ViewEngines.Razor.IHtmlString GetInputHtml(TextInputType inputType) { ///TODO: GB fix this so it renders the password with the correct attributes: if (inputType == TextInputType.Password) { return(new NonEncodedHtmlString(string.Format(@"<input type=""password"" id="""" name="""" class="""" />"))); } //return FieldGenerator.HtmlHelper.PasswordFor(FieldGenerator.FieldProperty, FieldConfiguration.HtmlAttributes); var attrs = new HtmlAttributes(FieldConfiguration.HtmlAttributes); attrs.Attr(type => inputType.ToString().ToLower()); return(!string.IsNullOrEmpty(FieldConfiguration.FormatString) ? FieldGenerator.HtmlHelper.TextBoxFor(FieldGenerator.FieldProperty, FieldConfiguration.FormatString, attrs.ToDictionary()) : FieldGenerator.HtmlHelper.TextBoxFor(FieldGenerator.FieldProperty, attrs.ToDictionary())); }
/// <inheritdoc /> public IFieldConfiguration Attr(string key, object value) { Attributes.Attr(key, value); return(this); }
public IFieldConfiguration Id(string id) { Attributes.Attr("id", id); return(this); }