Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PF-329 ( passwords match validation ) #68

Open
wants to merge 1 commit into
base: staging
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/Fields/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@ import context from './../../Store/Context'
import { getFieldValue } from '../../Helpers/global'
import { useNativeValidationMessage } from '../../Hooks/useNativeValidationMessage'

const Input = ({ id, type, initial, validation = {}, ...props }) => {
const Input = ({
id,
type,
initial,
validation = {},
matchPassword = {},
...props
}) => {
const { state, actions } = useContext(context)
const ref = useRef()
const { handleValidationChange, handleValidationBlur } =
useNativeValidationMessage()
const { handleChange, handleBlur, declareField } = actions
const { values, errors } = state
const { HTMLValidate } = validation
const isConfirm = `${id}`.includes('_confirm')

useEffect(() => {
const actualInitial = initial === undefined ? null : initial
Expand All @@ -23,9 +31,16 @@ const Input = ({ id, type, initial, validation = {}, ...props }) => {

useEffect(() => {
if (HTMLValidate === true) {
if (ref.current && errors[id] !== undefined)
if (isConfirm) {
const realId = id.split('_')[0]
if (values[id] !== values[realId]) {
ref.current.setCustomValidity(matchPassword?.msg)
}
} else if (ref.current && errors[id] !== undefined) {
ref.current.setCustomValidity(errors[id])
else if (ref.current) ref.current.setCustomValidity('')
} else if (ref.current) {
ref.current.setCustomValidity('')
}
}
}, [ref.current, errors])

Expand Down