Skip to content

Commit

Permalink
Merge pull request #33 from sinanbozkus/improvement/formhelper-initia…
Browse files Browse the repository at this point in the history
…lize-method-changed

Now on UseFormHelper function is not required
  • Loading branch information
sinanbozkus committed Jun 28, 2022
2 parents 2b9d78e + 0cb5397 commit f69a6a4
Show file tree
Hide file tree
Showing 9 changed files with 765 additions and 734 deletions.
8 changes: 1 addition & 7 deletions sample/FormHelper.Samples/Views/Home/HtmlHelper.cshtml
Expand Up @@ -26,7 +26,7 @@
@formConfig.FormTitle
</div>
<div class="card-body">
<form id="@formConfig.FormId" asp-controller="Home" asp-action="Save" enctype="multipart/form-data">
<form id="@formConfig.FormId" asp-controller="Home" asp-action="Save" enctype="multipart/form-data" formhelper>

<input type="hidden" asp-for="Id" />

Expand Down Expand Up @@ -74,12 +74,6 @@
@Html.RenderFormScript(formConfig)

<script>
//$('.formhelper').UseFormHelper({
//});
var ProductFormBeforeSubmit = function (rr, $form, options) {
console.log("BeforeSubmit function!");
}
Expand Down
34 changes: 15 additions & 19 deletions sample/FormHelper.Samples/Views/Home/TagHelper.cshtml
Expand Up @@ -13,15 +13,10 @@
</div>
<div class="card-body">
<!-- You can use <form asp-formhelper="true"> or <formhelper> to activate formhelper. -->
<form asp-formhelper="true"
asp-controller="Home"
asp-action="Save"
asp-dataType="FormData"
asp-callback="ProductFormCallback"
asp-beforeSubmit="ProductFormBeforeSubmit"
asp-enableButtonAfterSuccess="true"
asp-resetFormAfterSuccess="false"
enctype="multipart/form-data">
<form asp-formhelper="true" asp-controller="Home" asp-action="Save" asp-dataType="FormData"
asp-callback="ProductFormCallback" asp-beforeSubmit="ProductFormBeforeSubmit"
asp-enableButtonAfterSuccess="true" asp-resetFormAfterSuccess="false"
enctype="multipart/form-data">

<input type="hidden" asp-for="Id" />

Expand All @@ -32,7 +27,8 @@
</div>
<div class="form-group">
<label asp-for="Category"></label>
<select asp-for="Category" asp-items="Html.GetEnumSelectList<Category>()" class="form-control">
<select asp-for="Category" asp-items="Html.GetEnumSelectList<Category>()"
class="form-control">
<option value="">Select</option>
</select>
<span asp-validation-for="Category" class="text-danger"></span>
Expand Down Expand Up @@ -66,14 +62,14 @@


@section Scripts {
<script>
var ProductFormBeforeSubmit = function (rr, $form, options) {
console.log("BeforeSubmit function!");
}
<script>
var ProductFormBeforeSubmit = function (rr, $form, options) {
console.log("BeforeSubmit function!");
}
var ProductFormCallback = function (response, statusText, xhr, $form) {
console.log(response);
console.log("Callback function!");
}
</script>
var ProductFormCallback = function (response, statusText, xhr, $form) {
console.log(response);
console.log("Callback function!");
}
</script>
}
10 changes: 5 additions & 5 deletions src/FormHelper/FormHelper.csproj
Expand Up @@ -2,13 +2,13 @@

<PropertyGroup>
<PackageId>FormHelper</PackageId>
<Version>4.1.0-beta17</Version>
<Version>5.0.0-beta2</Version>
<Authors>Sinan BOZKUS</Authors>
<projectUrl>https://github.com/sinanbozkus/FormHelper</projectUrl>
<RepositoryUrl>https://github.com/sinanbozkus/FormHelper</RepositoryUrl>
<ProjectUrl>https://github.com/sinanbozkus/FormHelper</ProjectUrl>
<description>Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)</description>
<Copyright>Copyright (c) Sinan BOZKUS 2021</Copyright>
<Copyright>Copyright (c) Sinan BOZKUS 2022</Copyright>
<tags>fluentvalidation fluent validation form helper validation helper notification crud</tags>
<PackageIcon>formhelper-icon.png</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
Expand Down Expand Up @@ -63,8 +63,8 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

<!-- <ItemGroup>-->
<!-- <PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />-->
<!-- </ItemGroup>-->
<!-- <ItemGroup>
<PackageReference Include="BuildBundlerMinifier" Version="3.2.449" />
</ItemGroup> -->

</Project>
25 changes: 12 additions & 13 deletions src/FormHelper/Helpers/FormHelperHtmlHelpers.cs
Expand Up @@ -13,19 +13,18 @@ public static HtmlString RenderFormScript(this IHtmlHelper html, FormConfig conf
return new HtmlString($@"
<script>
$(document).ready(function () {{
var $form = $('#{config.FormId}');
$('#{config.FormId}').UseFormHelper({{
url: $form.attr('action'),
method: $form.attr('method'),
dataType: '{config.DataType}',
redirectDelay: {configuration.RedirectDelay},
beforeSubmit: '{config.BeforeSubmit}',
callback: '{config.Callback}',
enableButtonAfterSuccess: {(config.EnableButtonAfterSuccess ? "true" : "false")},
resetFormAfterSuccess: {(config.ResetFormAfterSuccess ? "true" : "false")},
checkTheFormFieldsMessage: '{configuration.CheckTheFormFieldsMessage}',
toastrPositionClass: '{(config.ToastrPosition == null ? configuration.ToastrDefaultPosition.ToClassName() : config.ToastrPosition.Value.ToClassName())}'
}});
const $form = $('#{config.FormId}');
$form.attr('formhelper')
$form.attr('dataType', '{config.DataType}');
$form.attr('CheckTheFormFieldsMessage', '{configuration.CheckTheFormFieldsMessage}');
$form.attr('redirectDelay', '{configuration.RedirectDelay}');
$form.attr('beforeSubmit', '{config.BeforeSubmit}');
$form.attr('callback', '{config.Callback}');
$form.attr('enableButtonAfterSuccess', '{config.EnableButtonAfterSuccess}');
$form.attr('resetFormAfterSuccess', '{config.ResetFormAfterSuccess}');
$form.attr('toastrPositionClass', '{(config.ToastrPosition == null ? configuration.ToastrDefaultPosition.ToClassName() : config.ToastrPosition.Value.ToClassName())}');
}});
</script>
");
Expand Down
2 changes: 1 addition & 1 deletion src/FormHelper/Scripts/formhelper.bundle.min.js

Large diffs are not rendered by default.

0 comments on commit f69a6a4

Please sign in to comment.