This repository has been archived by the owner on Aug 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Nevoss/dev
Version PR - v0.4.0
- Loading branch information
Showing
41 changed files
with
4,814 additions
and
5,769 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
node_modules | ||
npm-debug.log | ||
.idea | ||
lib |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ErrorsStack } from "../types"; | ||
export declare class Errors { | ||
/** | ||
* Errors stack, holds all the form errors | ||
*/ | ||
$errors: ErrorsStack; | ||
/** | ||
* Construct the Errors class with errors | ||
* | ||
* @param errors | ||
*/ | ||
constructor(errors?: ErrorsStack); | ||
/** | ||
* Record errors to the ErrorsStack | ||
* | ||
* @param errors | ||
*/ | ||
record(errors: ErrorsStack): Errors; | ||
/** | ||
* Append errors to the ErrorsStack | ||
* | ||
* @param errors | ||
*/ | ||
append(errors: ErrorsStack): Errors; | ||
/** | ||
* checks if fieldKey exists in the ErrorsStack | ||
* | ||
* @param fieldKey | ||
*/ | ||
has(fieldKey: string): boolean; | ||
/** | ||
* Returns array of errors for specific field | ||
* | ||
* @param fieldKey | ||
* @param defaultValue | ||
*/ | ||
get(fieldKey: string, defaultValue?: any): string[]; | ||
/** | ||
* returns first error of specific field key | ||
* | ||
* @param fieldKey | ||
* @param defaultValue | ||
*/ | ||
getFirst<T>(fieldKey: string, defaultValue?: T): T | string; | ||
/** | ||
* Returns all the ErrorsStack | ||
*/ | ||
all(): ErrorsStack; | ||
/** | ||
* delete a key from ErrorsStack | ||
* | ||
* @param fieldKey | ||
*/ | ||
clearField(fieldKey: string): Errors; | ||
/** | ||
* check if there is any error in the ErrorsStack | ||
*/ | ||
any(): boolean; | ||
/** | ||
* Clear the ErrorsStack object | ||
*/ | ||
clear(): Errors; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Errors { | ||
/** | ||
* Construct the Errors class with errors | ||
* | ||
* @param errors | ||
*/ | ||
constructor(errors = {}) { | ||
this.record(errors); | ||
} | ||
/** | ||
* Record errors to the ErrorsStack | ||
* | ||
* @param errors | ||
*/ | ||
record(errors) { | ||
this.$errors = Object.assign({}, errors); | ||
return this; | ||
} | ||
/** | ||
* Append errors to the ErrorsStack | ||
* | ||
* @param errors | ||
*/ | ||
append(errors) { | ||
this.$errors = Object.assign({}, this.$errors, errors); | ||
return this; | ||
} | ||
/** | ||
* checks if fieldKey exists in the ErrorsStack | ||
* | ||
* @param fieldKey | ||
*/ | ||
has(fieldKey) { | ||
return this.$errors.hasOwnProperty(fieldKey); | ||
} | ||
/** | ||
* Returns array of errors for specific field | ||
* | ||
* @param fieldKey | ||
* @param defaultValue | ||
*/ | ||
get(fieldKey, defaultValue = []) { | ||
if (!this.has(fieldKey)) { | ||
return defaultValue; | ||
} | ||
return this.$errors[fieldKey]; | ||
} | ||
/** | ||
* returns first error of specific field key | ||
* | ||
* @param fieldKey | ||
* @param defaultValue | ||
*/ | ||
getFirst(fieldKey, defaultValue = null) { | ||
const errors = this.get(fieldKey); | ||
return errors.length <= 0 ? defaultValue : errors[0]; | ||
} | ||
/** | ||
* Returns all the ErrorsStack | ||
*/ | ||
all() { | ||
return this.$errors; | ||
} | ||
/** | ||
* delete a key from ErrorsStack | ||
* | ||
* @param fieldKey | ||
*/ | ||
clearField(fieldKey) { | ||
if (this.has(fieldKey)) { | ||
delete this.$errors[fieldKey]; | ||
this.$errors = Object.assign({}, this.$errors); | ||
} | ||
return this; | ||
} | ||
/** | ||
* check if there is any error in the ErrorsStack | ||
*/ | ||
any() { | ||
return Object.keys(this.$errors).length > 0; | ||
} | ||
/** | ||
* Clear the ErrorsStack object | ||
*/ | ||
clear() { | ||
this.$errors = {}; | ||
return this; | ||
} | ||
} | ||
exports.Errors = Errors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { Errors } from "./Errors"; | ||
import { Validator } from "./Validator"; | ||
import { Options, SubmitCallback } from "../types"; | ||
export declare class Form { | ||
/** | ||
* Defaults options for the Form instance | ||
*/ | ||
static defaults: Options; | ||
/** | ||
* determine if the form is on submitting mode | ||
*/ | ||
$submitting: boolean; | ||
/** | ||
* Errors class - handling all the errors of the fields | ||
*/ | ||
$errors: Errors; | ||
/** | ||
* Validator class - handling all the validations stuff | ||
*/ | ||
$validator: Validator; | ||
/** | ||
* Holds all the labels of the fields | ||
*/ | ||
$labels: Object; | ||
/** | ||
* The initiate data that was provide to the form | ||
*/ | ||
$originalData: Object; | ||
/** | ||
* all the extra data that provide in the construction of this class | ||
* will be hold here. | ||
*/ | ||
$extra: Object; | ||
/** | ||
* Options of the Form | ||
*/ | ||
$options: Options; | ||
/** | ||
* constructor of the class | ||
* | ||
* @param data | ||
* @param options | ||
*/ | ||
constructor(data: Object, options?: Options); | ||
/** | ||
* Init the form | ||
* fill all the data that should be filled (Validator, OriginalData etc..( | ||
* | ||
* @param data | ||
*/ | ||
private init; | ||
/** | ||
* Set all the fields value same as $originalData fields value | ||
*/ | ||
reset(): Form; | ||
/** | ||
* get all the data of the form | ||
*/ | ||
data(): Object; | ||
/** | ||
* fill the Form data with new data. | ||
* without remove another fields data. | ||
* | ||
* @param newData | ||
*/ | ||
fill(newData: Object): Form; | ||
/** | ||
* validate specific key or the whole form. | ||
* | ||
* @param fieldKey | ||
*/ | ||
validate(fieldKey?: string | null): boolean; | ||
/** | ||
* validate specific field | ||
* | ||
* @param fieldKey | ||
*/ | ||
validateField(fieldKey: string): boolean; | ||
/** | ||
* validate all the fields of the form | ||
*/ | ||
validateAll(): boolean; | ||
/** | ||
* build Field object | ||
* | ||
* @param fieldKey | ||
*/ | ||
private buildFieldObject; | ||
/** | ||
* assign options to Options object | ||
* | ||
* @param options | ||
*/ | ||
assignOptions(options: Options): this; | ||
/** | ||
* submit the form, this method received a callback that | ||
* will submit the form and must return a Promise. | ||
* | ||
* @param callback | ||
*/ | ||
submit(callback: SubmitCallback): Promise<any>; | ||
/** | ||
* Successful submission method | ||
* | ||
* @param response | ||
*/ | ||
private successfulSubmission; | ||
/** | ||
* UnSuccessful submission method | ||
* | ||
* @param error | ||
*/ | ||
private unSuccessfulSubmission; | ||
/** | ||
* Hook for successful submission | ||
* use Form.successfulSubmissionHook = () => {}; | ||
* for extending the successful submission handling | ||
* | ||
* @param response | ||
* @param form | ||
*/ | ||
static successfulSubmissionHook(response: any, form: Form): Promise<any>; | ||
/** | ||
* Hook for un successful submission | ||
* use Form.unSuccessfulSubmissionHook = () => {}; | ||
* for extending the un successful submission handling | ||
* | ||
* @param error | ||
* @param form | ||
*/ | ||
static unSuccessfulSubmissionHook(error: any, form: Form): Promise<any>; | ||
} |
Oops, something went wrong.