@rsuci/shared-form-components 1.0.98 → 1.0.99
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* RSU v2 - Moteur de Rendu des Formulaires d'Enquête
|
|
4
4
|
*
|
|
5
5
|
* Formats acceptés :
|
|
6
|
-
* - Nouveau format :
|
|
7
|
-
* - Ancien format : C
|
|
6
|
+
* - Nouveau format : CI00XXXXXXX (CI00 + 7 chiffres) = 11 caractères
|
|
7
|
+
* - Ancien format : C XXXX XXXX XX (C + espace + 4 chiffres + espace + 4 chiffres + espace + 2 chiffres) = 14 caractères
|
|
8
8
|
*/
|
|
9
9
|
import React from 'react';
|
|
10
10
|
import { VariableFormulaire, VariableValue } from '../../types/enquete';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CNIInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/CNIInput.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAgC,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIxE,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,kBAAkB,GAAG;QAAE,QAAQ,EAAE,KAAK,CAAA;KAAE,CAAC;IACnD,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;
|
|
1
|
+
{"version":3,"file":"CNIInput.d.ts","sourceRoot":"","sources":["../../../src/components/inputs/CNIInput.tsx"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAgC,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIxE,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,kBAAkB,GAAG;QAAE,QAAQ,EAAE,KAAK,CAAA;KAAE,CAAC;IACnD,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACzC,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAiED,QAAA,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAgHrC,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* RSU v2 - Moteur de Rendu des Formulaires d'Enquête
|
|
4
4
|
*
|
|
5
5
|
* Formats acceptés :
|
|
6
|
-
* - Nouveau format :
|
|
7
|
-
* - Ancien format : C
|
|
6
|
+
* - Nouveau format : CI00XXXXXXX (CI00 + 7 chiffres) = 11 caractères
|
|
7
|
+
* - Ancien format : C XXXX XXXX XX (C + espace + 4 chiffres + espace + 4 chiffres + espace + 2 chiffres) = 14 caractères
|
|
8
8
|
*/
|
|
9
9
|
'use client';
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
@@ -12,7 +12,7 @@ import { useState, useCallback } from 'react';
|
|
|
12
12
|
import { applyComponentStyle } from '../../utils/styleUtils';
|
|
13
13
|
import { isComponentReadonly, readonlyClasses } from '../../utils/componentStateUtils';
|
|
14
14
|
const CNI_NEW_REGEX = /^CI00\d{7}$/;
|
|
15
|
-
const CNI_OLD_REGEX = /^C
|
|
15
|
+
const CNI_OLD_REGEX = /^C \d{4} \d{4} \d{2}$/;
|
|
16
16
|
const applyNewFormatMask = (value) => {
|
|
17
17
|
let result = value.toUpperCase();
|
|
18
18
|
result = result.replace(/[^CI0-9]/g, '');
|
|
@@ -33,7 +33,6 @@ const applyNewFormatMask = (value) => {
|
|
|
33
33
|
const applyOldFormatMask = (value) => {
|
|
34
34
|
let result = value.toUpperCase();
|
|
35
35
|
const chars = [];
|
|
36
|
-
let rawIndex = 0;
|
|
37
36
|
for (let i = 0; i < result.length && chars.length < 14; i++) {
|
|
38
37
|
const char = result[i];
|
|
39
38
|
const pos = chars.length;
|
|
@@ -42,28 +41,41 @@ const applyOldFormatMask = (value) => {
|
|
|
42
41
|
chars.push(char);
|
|
43
42
|
}
|
|
44
43
|
else if (pos === 1) {
|
|
44
|
+
// Auto-insérer espace après C
|
|
45
45
|
chars.push(' ');
|
|
46
46
|
if (/[0-9]/.test(char))
|
|
47
47
|
chars.push(char);
|
|
48
48
|
else
|
|
49
49
|
i--;
|
|
50
50
|
}
|
|
51
|
-
else if (pos
|
|
52
|
-
|
|
51
|
+
else if (pos >= 2 && pos <= 5) {
|
|
52
|
+
// 4 chiffres libres
|
|
53
|
+
if (/[0-9]/.test(char))
|
|
53
54
|
chars.push(char);
|
|
54
55
|
}
|
|
55
|
-
else if (pos ===
|
|
56
|
+
else if (pos === 6) {
|
|
57
|
+
// Auto-insérer espace après les 4 premiers chiffres
|
|
58
|
+
chars.push(' ');
|
|
56
59
|
if (/[0-9]/.test(char))
|
|
57
60
|
chars.push(char);
|
|
61
|
+
else
|
|
62
|
+
i--;
|
|
58
63
|
}
|
|
59
|
-
else if (pos
|
|
64
|
+
else if (pos >= 7 && pos <= 10) {
|
|
65
|
+
// 4 chiffres libres
|
|
66
|
+
if (/[0-9]/.test(char))
|
|
67
|
+
chars.push(char);
|
|
68
|
+
}
|
|
69
|
+
else if (pos === 11) {
|
|
70
|
+
// Auto-insérer espace après les 4 seconds chiffres
|
|
60
71
|
chars.push(' ');
|
|
61
72
|
if (/[0-9]/.test(char))
|
|
62
73
|
chars.push(char);
|
|
63
74
|
else
|
|
64
75
|
i--;
|
|
65
76
|
}
|
|
66
|
-
else if (pos >=
|
|
77
|
+
else if (pos >= 12 && pos <= 13) {
|
|
78
|
+
// 2 derniers chiffres
|
|
67
79
|
if (/[0-9]/.test(char))
|
|
68
80
|
chars.push(char);
|
|
69
81
|
}
|
|
@@ -130,7 +142,7 @@ const CNIInput = ({ variable, value, onChange, onBlur, error, disabled, isConsul
|
|
|
130
142
|
setLocalError('Format attendu : CI00 suivi de 7 chiffres (ex: CI001234567)');
|
|
131
143
|
}
|
|
132
144
|
else if (format === 'old') {
|
|
133
|
-
setLocalError('Format attendu : C
|
|
145
|
+
setLocalError('Format attendu : C XXXX XXXX XX (ex: C 1234 5678 90)');
|
|
134
146
|
}
|
|
135
147
|
else {
|
|
136
148
|
setLocalError('Format CNI invalide');
|
|
@@ -152,7 +164,7 @@ const CNIInput = ({ variable, value, onChange, onBlur, error, disabled, isConsul
|
|
|
152
164
|
return `${baseClasses} ${errorClasses} bg-white`;
|
|
153
165
|
};
|
|
154
166
|
const displayError = error || localError;
|
|
155
|
-
const placeholder = 'CI001234567 ou C
|
|
167
|
+
const placeholder = 'CI001234567 ou C 1234 5678 90';
|
|
156
168
|
return (_jsxs("div", { style: containerStyle, children: [_jsx("input", { type: "text", value: stringValue, onChange: handleChange, onBlur: handleBlur, placeholder: disabled ? '' : placeholder, disabled: disabled, readOnly: isReadonly, style: textStyle, className: getInputClasses(), maxLength: 14, autoComplete: "off", spellCheck: false }), displayError && (_jsx("p", { className: "mt-1 text-sm text-red-500", children: displayError }))] }));
|
|
157
169
|
};
|
|
158
170
|
export default CNIInput;
|
package/package.json
CHANGED