-
Notifications
You must be signed in to change notification settings - Fork 1
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 #1 from capdilla/3.x.x
version 3.0.0
- Loading branch information
Showing
8 changed files
with
76 additions
and
78 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
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,61 +1,61 @@ | ||
import React from "react"; | ||
import { IFormComponent } from "../types"; | ||
import React from 'react' | ||
import { FormComponent } from '../index' | ||
|
||
const getErrorMessage = (validation: any, name: string) => { | ||
if (validation) { | ||
return validation[name] && validation[name].errorMessage | ||
? validation[name].errorMessage | ||
: "Required"; | ||
: 'Required' | ||
} | ||
|
||
return ""; | ||
}; | ||
return '' | ||
} | ||
|
||
const getValidation = ( | ||
validation: any, | ||
name: string, | ||
showValidation: boolean | ||
showValidation: boolean, | ||
) => { | ||
if (showValidation && validation) { | ||
if (validation[name] && !validation[name].isValid) { | ||
return "error"; | ||
return 'error' | ||
} else { | ||
return null; | ||
return null | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
return null | ||
} | ||
|
||
const getError = ( | ||
name: string, | ||
showValidation: boolean, | ||
usedFields: any, | ||
validation: any | ||
validation: any, | ||
) => { | ||
// return false | ||
|
||
let valid = getValidation(validation, name, true); | ||
const errorMessage = getErrorMessage(validation, name); | ||
let valid = getValidation(validation, name, true) | ||
const errorMessage = getErrorMessage(validation, name) | ||
|
||
if (usedFields && usedFields.includes(name) && valid == "error") { | ||
return { content: errorMessage }; | ||
if (usedFields && usedFields.includes(name) && valid == 'error') { | ||
return { content: errorMessage } | ||
} | ||
|
||
return showValidation && valid == "error" ? { content: errorMessage } : false; | ||
}; | ||
return showValidation && valid == 'error' ? { content: errorMessage } : false | ||
} | ||
|
||
export const withError = <P extends IFormComponent>( | ||
Comp: React.ComponentType<P> | ||
export const withError = <P extends FormComponent>( | ||
Comp: React.ComponentType<P>, | ||
) => { | ||
return (props: P): any => { | ||
const error = getError( | ||
props.name, | ||
props.showValidation == true, | ||
props.usedFields, | ||
props.validationForm | ||
) as { content: string } | undefined; | ||
props.validationForm, | ||
) as { content: string } | undefined | ||
|
||
return <Comp {...props} error={error} />; | ||
}; | ||
}; | ||
return <Comp {...props} error={error} /> | ||
} | ||
} |
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,9 +1,8 @@ | ||
import Core, { GetComponent } from "./lib/core"; | ||
import ReactDForm from "./react-web"; | ||
import { withError } from "./helpers/getError"; | ||
import { IFormComponent, IFormData, IFields } from "./types"; | ||
export type FormComponent = IFormComponent; | ||
import Core, { GetComponent } from './lib/core' | ||
import ReactDForm from './react-web' | ||
export * from './helpers/getError' | ||
export * from './types' | ||
|
||
export default Core; | ||
export default Core | ||
|
||
export { GetComponent, ReactDForm, withError, IFormData, IFields }; | ||
export { GetComponent, ReactDForm } |
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
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
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
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
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