This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -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;
}
}
}