Skip to content

Instantly share code, notes, and snippets.

@bsatrom
Created September 1, 2011 21:34
Show Gist options
  • Save bsatrom/1187346 to your computer and use it in GitHub Desktop.
Save bsatrom/1187346 to your computer and use it in GitHub Desktop.
HTML5 Web Forms, ASP.NET MVC and MvcContrib
<fieldset>
<legend>Place Your Order</legend>
Name: @this.TextBox(m => m.Name).Required(true).Autofocus(true).Placeholder("ex. Hugo Reyes")
Email: @this.EmailBox(m => m.Email).Required(true).Placeholder("ex. [email protected]")
Website: @this.UrlBox(m => m.Website).Placeholder("ex. http://www.domain.com")
Phone: @this.TelephoneBox(m => m.Phone).Pattern(@"\(\d\d\d\) \d\d\d\-\d\d\d\d").Title("(xxx) xxx-xxxx")
Requested Delivery Date: @this.DatePicker(m => m.DeliveryDate).Required(true)
Shipping Address: @this.TextArea(m => m.Address)
Quantity: @this.NumberBox(m => m.Quantity).Limit(1, 10, 1)
@this.SubmitButton("Place Order")
@this.SubmitButton("Save For Later").FormNoValidate(true).Id("saveForLater")
</fieldset>
public class FluentHtml5ViewPage<T> : ModelViewPage<T> where T : class
{
public FluentHtml5ViewPage()
: base(new RegularExpressionBehavior(), new RangeBehavior(), new RequiredBehavior()){}
}
<fieldset>
<legend>Place Your Order</legend>
Name: @this.TextBox(m => m.Name).Autofocus(true).Placeholder("ex. Hugo Reyes")
Email: @this.EmailBox(m => m.Email).Placeholder("ex. [email protected]")
Website: @this.UrlBox(m => m.Website).Placeholder("ex. http://www.domain.com")
Phone: @this.TelephoneBox(m => m.Phone).Title("(xxx) xxx-xxxx")
Requested Delivery Date: @this.DatePicker(m => m.DeliveryDate).Required(true)
Shipping Address: @this.TextArea(m => m.Address)
Quantity: @this.NumberBox(m => m.Quantity)
@this.SubmitButton("Place Order")
@this.SubmitButton("Save For Later").FormNoValidate(true).Id("saveForLater")
</fieldset>
public class Order
{
[Required]
public int Id { get; set; }
[Required]
public int ItemId { get; set; }
[Required]
public string Name { get; set; }
[Required]
public string Email { get; set; }
public string Website { get; set; }
[RegularExpression(@"\(\d\d\d\) \d\d\d\-\d\d\d\d")]
public string Phone { get; set; }
[Required]
public DateTime DeliveryDate { get; set; }
public string Address { get; set; }
Range(1, 10)]
public int Quantity { get; set; }
}
<fieldset>
<legend>Place Your Order</legend>
Name: <input type="text" id="orderName" required autofocus placeholder="ex. Hugo Reyes" />
Email: <input type="email" id="orderEmail" required placeholder="ex. [email protected]" />
Website: <input type="url" id="orderWebsite" placeholder="ex. http://www.domain.com" />
Phone: <input type="tel" class="field" pattern="\(\d\d\d\) \d\d\d\-\d\d\d\d" title="(xxx) xxx-xxxx" />
Requested Delivery Date: <input type="date" id="deliveryDate" required />
Shipping Address: <textarea rows="4" cols="20" id="orderShipping" required></textarea>
Quantity: <input type="number" id="orderQty" name="orderQty" min=1 max=10 step=1 value=1 />
<input type="submit" value="Place Order" />
<input type="submit" formnovalidate value="Save for Later" id="saveForLater" />
</fieldset>
public class RegularExpressionBehavior : IBehavior<IMemberElement>
{
public void Execute(IMemberElement element)
{
var attribute = element.GetAttribute<RegularExpressionAttribute>();
if (attribute != null)
{
element.SetAttr(HtmlAttribute.Pattern, attribute.Pattern);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment