init
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Mvc.Html;
|
||||
|
||||
namespace Kreta.Web.Helpers
|
||||
{
|
||||
public static class FormExtensions
|
||||
{
|
||||
public static MvcForm KretaForm(this HtmlHelper htmlHelper, string name, Dictionary<string, object> htmlAttributes = null)
|
||||
{
|
||||
if (htmlAttributes == null)
|
||||
htmlAttributes = new Dictionary<string, object>();
|
||||
|
||||
htmlAttributes.Add("id", name);
|
||||
htmlAttributes.Add("onsubmit", "return false");
|
||||
|
||||
var mvcForm = htmlHelper.BeginForm(null, null, FormMethod.Get, htmlAttributes);
|
||||
var formName = "#" + name;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.Append("<script>$.validator.setDefaults({ ignore: [] });</script>");
|
||||
sb.AppendFormat("<script>KretaForm.validate($('{0}'));</script>", formName);
|
||||
|
||||
htmlHelper.ViewContext.Writer.Write(sb.ToString());
|
||||
|
||||
sb.Append("</form>");
|
||||
|
||||
return mvcForm;
|
||||
}
|
||||
|
||||
public static MvcForm KretaForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, string name, Dictionary<string, object> htmlAttributes = null)
|
||||
{
|
||||
if (htmlAttributes == null)
|
||||
htmlAttributes = new Dictionary<string, object>();
|
||||
|
||||
htmlAttributes.Add("id", name);
|
||||
|
||||
var mvcForm = htmlHelper.BeginForm(actionName, controllerName, method, htmlAttributes);
|
||||
var formName = "#" + name;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.Append("<script>$.validator.setDefaults({ ignore: [] });</script>");
|
||||
sb.AppendFormat("<script>KretaForm.validate($('{0}'));</script>", formName);
|
||||
|
||||
htmlHelper.ViewContext.Writer.Write(sb.ToString());
|
||||
|
||||
return mvcForm;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user