diff --git a/src/components/commun/Datepicker.jsx b/src/components/commun/Datepicker.jsx
index f13d28a..9160c39 100644
--- a/src/components/commun/Datepicker.jsx
+++ b/src/components/commun/Datepicker.jsx
@@ -1,13 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
-export default function Datepicker({ children, id, isRequired = true, onChange, min }) {
+export default function Datepicker({ children, id, isRequired = true, onChange, min, error }) {
return (
-
+
+ {error && (
+
+ {error}
+
+ )}
);
}
@@ -19,4 +24,5 @@ Datepicker.propTypes = {
onChange: PropTypes.func,
min: PropTypes.string,
name: PropTypes.string,
+ error: PropTypes.string
};
diff --git a/src/components/commun/Input.jsx b/src/components/commun/Input.jsx
index e972c23..8a11693 100644
--- a/src/components/commun/Input.jsx
+++ b/src/components/commun/Input.jsx
@@ -1,11 +1,27 @@
import React from 'react';
import PropTypes from 'prop-types';
-export default function Input({ children, id, isRequired = true, autoComplete = 'on', testId = '', type = 'text',
- pattern, onChange, list, min, disabled, isLoading, ariaBusy, value, maxlength }) {
+export default function Input({
+ children,
+ id,
+ isRequired = true,
+ autoComplete = 'on',
+ testId = '',
+ type = 'text',
+ pattern,
+ onChange,
+ list,
+ min,
+ disabled,
+ isLoading,
+ ariaBusy,
+ value,
+ maxlength,
+ error,
+}) {
return (
-
)}
+ {error && (
+
+ {error}
+
+ )}
);
@@ -49,5 +70,6 @@ Input.propTypes = {
ariaBusy: PropTypes.bool,
value: PropTypes.string,
testId: PropTypes.string,
- maxlength: PropTypes.string
+ maxlength: PropTypes.string,
+ error: PropTypes.string
};
diff --git a/src/components/commun/ZoneDeTexte.jsx b/src/components/commun/ZoneDeTexte.jsx
index 5c6bfc9..9f5caf8 100644
--- a/src/components/commun/ZoneDeTexte.jsx
+++ b/src/components/commun/ZoneDeTexte.jsx
@@ -1,13 +1,18 @@
import React from 'react';
import PropTypes from 'prop-types';
-export default function ZoneDeTexte({ children, id, isRequired = true, maxlength = "2500" }) {
+export default function ZoneDeTexte({ children, id, isRequired = true, maxlength = '2500', error }) {
return (
-
+
+ {error && (
+
+ {error}
+
+ )}
);
}
@@ -17,4 +22,5 @@ ZoneDeTexte.propTypes = {
id: PropTypes.string,
isRequired: PropTypes.bool,
maxlength: PropTypes.string,
+ error: PropTypes.string,
};
diff --git a/src/shared/checkValidity.js b/src/shared/checkValidity.js
new file mode 100644
index 0000000..9cc88e0
--- /dev/null
+++ b/src/shared/checkValidity.js
@@ -0,0 +1,9 @@
+export const checkValidity = (ref, setErrors) => {
+ const formData = new FormData(ref.current);
+ const keys = Array.from(formData.keys());
+ const formElements = keys.map(key => document.getElementById(key)).filter(key => key !== null);
+ const errors = formElements.map(formElement => ({
+ [formElement.id]: formElement.validationMessage,
+ }));
+ setErrors(Object.assign({}, ...errors));
+};
diff --git a/src/views/candidature-conseiller/AddressChooser.jsx b/src/views/candidature-conseiller/AddressChooser.jsx
index 9594c76..aaf03db 100644
--- a/src/views/candidature-conseiller/AddressChooser.jsx
+++ b/src/views/candidature-conseiller/AddressChooser.jsx
@@ -2,17 +2,19 @@ import React, { useState } from 'react';
import Input from '../../components/commun/Input';
import { useGeoApi } from './useGeoApi';
import { debounce } from './debounce';
+import PropTypes from 'prop-types';
-export default function AddressChooser() {
+export default function AddressChooser({ error }) {
const { searchByName, villes } = useGeoApi();
const [codeCommune, setCodeCommune] = useState('');
return (
<>
{
if (event.target.value.length >= 3) {
searchByName(event.target.value);
@@ -25,7 +27,7 @@ export default function AddressChooser() {
Votre lieu d’habitation
*{' '}
Saississez le nom ou le code postal de votre commune.
-
+
}
-