Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/SinanBozkus/FormHelper
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)
https://github.com/SinanBozkus/FormHelper
asp-net-core aspnet-core aspnet-core-mvc aspnet-core-validator aspnet-mvc aspnetcore dotnet fluent-validation fluent-validation-client-side fluentvalidation fluentvalidation-clientside form form-validation form-validator formhelper javascript netcore validation validator
Last synced: about 2 months ago
JSON representation
ASP.NET Core - Transform server-side validations to client-side without writing any javascript code. (Compatible with Fluent Validation)
- Host: GitHub
- URL: https://github.com/SinanBozkus/FormHelper
- Owner: sinanbozkus
- License: mit
- Created: 2019-05-04T19:33:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-11-29T12:49:52.000Z (about 2 years ago)
- Last Synced: 2024-08-01T05:15:48.399Z (4 months ago)
- Topics: asp-net-core, aspnet-core, aspnet-core-mvc, aspnet-core-validator, aspnet-mvc, aspnetcore, dotnet, fluent-validation, fluent-validation-client-side, fluentvalidation, fluentvalidation-clientside, form, form-validation, form-validator, formhelper, javascript, netcore, validation, validator
- Language: JavaScript
- Homepage:
- Size: 292 KB
- Stars: 270
- Watchers: 22
- Forks: 35
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: License.txt
Awesome Lists containing this project
- awesome-dotnet-core - FormHelper - ASP.NET Core的表单和验证帮助器。表单助手可帮助您创建Ajax表单和验证,而无需编写任何JavaScript代码。 (框架, 库和工具 / 大杂烩)
- fucking-awesome-dotnet-core - FormHelper - Form & Validation Helper for ASP.NET Core. Form Helper helps you to create ajax forms and validations without writing any javascript code. (Compatible with Fluent Validation). (Frameworks, Libraries and Tools / Misc)
- awesome-dotnet-core - FormHelper - Form & Validation Helper for ASP.NET Core. Form Helper helps you to create ajax forms and validations without writing any javascript code. (Compatible with Fluent Validation). (Frameworks, Libraries and Tools / Misc)
README
# Form Helper
### \#1 Form Library for ASP.NET Core MVC
If you like this library and want to support it, please give a star. :star:
Form & Validation Helper for **ASP.NET Core MVC**
Form Helper helps you to create ajax forms and validations without writing any javascript code. **It transforms server-side validations to client-side.** You can also use the form validator without ajax.
### **Compatible with Fluent Validation** :white_check_mark:
(You can add client-side validation support to Fluent Validation.)[![NuGet](https://img.shields.io/nuget/v/FormHelper.svg)](https://nuget.org/packages/FormHelper) [![Nuget](https://img.shields.io/nuget/dt/FormHelper.svg)](https://nuget.org/packages/FormHelper)
## Installation
FormHelper can be installed using the *Nuget Package Manager* or the *dotnet CLI*.
Package Manager:
```
Install-Package FormHelper
```dotnet CLI:
```csharp
dotnet add package FormHelper
```This library works with [jQuery](https://jquery.com)
CDN:
```html```
## Usage
**Startup.cs**
ConfigureServices:
```
services.AddControllersWithViews().AddFormHelper();
```
*With configuration: (optional)*
```
services.AddControllersWithViews().AddFormHelper(options => {
options.CheckTheFormFieldsMessage = "Your custom message...";
options.RedirectDelay = 6000;
options.EmbeddedFiles = true;
options.ToastrDefaultPosition = ToastrPosition.TopFullWidth;
});
```
Configure:
```app.UseFormHelper();
```**ViewImports.cshtml**
```csharp
@using FormHelper
@addTagHelper *, FormHelper
```**View: (TagHelper)**
```csharp//
// You can use or to activate formhelper.
// Optional parameters:
// asp-callback="javascriptFunctionName", asp-beforeSubmit="javascriptFunctionName", asp-dataType="FormData/Json", asp-enableButtonAfterSuccess="false", asp-resetFormAfterSuccess="true" asp-toastrPosition="ToastrPosition.BottomRight"
```**Controller:**
```csharp
[FormValidator]
public IActionResult Save(FormViewModel viewModel)// If you use Json data type, you need to add [FromBody] attribute.
// public IActionResult Save([FromBody]FormViewModel viewModel)
```**Return a result from Controller:**
Error Message:
```
return FormResult.CreateErrorResult("An error occured.");
```
Success Message:
```
return FormResult.CreateSuccessResult("Product saved.");
```
Success Message with Redirect:
```
return FormResult.CreateSuccessResult("Product saved. Please wait...", Url.Action("Home", "Index"));
```
Success Message with Redirect and Delay Time:
```
return FormResult.CreateSuccessResult("Product saved. Please wait...", Url.Action("Home", "Index"), 10000); // 10 seconds
```**Fill the form fields from a json object:**
```
$("#formId").fillFormFields(yourJsonObject);
```**Reset form and clear error messages:**
```
$("#formId").fhReset();
```**Toastr:**
Success:
```
fhToastr.success("Text here");
```
Warning:
```
fhToastr.warning("Text here");
```
Information:
```
fhToastr.information("Text here");
```
Error:
```
fhToastr.error("Text here");
```