@apia/validations 3.0.1 → 3.0.6
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.
- package/dist/{da.js → da-DqVKtoV2.js} +1 -1
- package/dist/da-DqVKtoV2.js.map +1 -0
- package/dist/{de.js → de-CcX9-Rq3.js} +1 -1
- package/dist/de-CcX9-Rq3.js.map +1 -0
- package/dist/{en.js → en-DCSKN2q5.js} +1 -1
- package/dist/en-DCSKN2q5.js.map +1 -0
- package/dist/{es.js → es-C-AXrgsF.js} +1 -1
- package/dist/es-C-AXrgsF.js.map +1 -0
- package/dist/{fa.js → fa-CpOxXp-C.js} +1 -1
- package/dist/fa-CpOxXp-C.js.map +1 -0
- package/dist/{fr.js → fr-cmPfrK5Y.js} +1 -1
- package/dist/fr-cmPfrK5Y.js.map +1 -0
- package/dist/{gr.js → gr-CmqXMJsZ.js} +1 -1
- package/dist/gr-CmqXMJsZ.js.map +1 -0
- package/dist/{hr.js → hr-DIdEoOl4.js} +1 -1
- package/dist/hr-DIdEoOl4.js.map +1 -0
- package/dist/{hu.js → hu-VYwXwEzb.js} +1 -1
- package/dist/hu-VYwXwEzb.js.map +1 -0
- package/dist/index.d.ts +785 -25
- package/dist/index.js +195 -123
- package/dist/index.js.map +1 -1
- package/dist/{it.js → it-CZNo0Ds3.js} +1 -1
- package/dist/it-CZNo0Ds3.js.map +1 -0
- package/dist/{ja.js → ja-CK5iBGzP.js} +1 -1
- package/dist/ja-CK5iBGzP.js.map +1 -0
- package/dist/{jp.js → jp-CK5iBGzP.js} +1 -1
- package/dist/jp-CK5iBGzP.js.map +1 -0
- package/dist/{nl.js → nl-BSU5Z9PJ.js} +1 -1
- package/dist/nl-BSU5Z9PJ.js.map +1 -0
- package/dist/{pl.js → pl-BSq2_6nm.js} +1 -1
- package/dist/pl-BSq2_6nm.js.map +1 -0
- package/dist/{pt.js → pt-DJTrqO4_.js} +1 -1
- package/dist/pt-DJTrqO4_.js.map +1 -0
- package/dist/{ro.js → ro-CAAZmoW6.js} +1 -1
- package/dist/ro-CAAZmoW6.js.map +1 -0
- package/package.json +6 -6
- package/rollup.validations.mjs +3 -3
- package/dist/collector/Collector.d.ts +0 -34
- package/dist/collector/Collector.d.ts.map +0 -1
- package/dist/collector/CollectorField.d.ts +0 -41
- package/dist/collector/CollectorField.d.ts.map +0 -1
- package/dist/collector/ValidatedCollectorField.d.ts +0 -44
- package/dist/collector/ValidatedCollectorField.d.ts.map +0 -1
- package/dist/collector/fields/Button.d.ts +0 -13
- package/dist/collector/fields/Button.d.ts.map +0 -1
- package/dist/collector/fields/Checkbox.d.ts +0 -13
- package/dist/collector/fields/Checkbox.d.ts.map +0 -1
- package/dist/collector/fields/Input.d.ts +0 -11
- package/dist/collector/fields/Input.d.ts.map +0 -1
- package/dist/collector/fields/Label.d.ts +0 -13
- package/dist/collector/fields/Label.d.ts.map +0 -1
- package/dist/collector/fields/Select.d.ts +0 -26
- package/dist/collector/fields/Select.d.ts.map +0 -1
- package/dist/collector/fields/Textarea.d.ts +0 -11
- package/dist/collector/fields/Textarea.d.ts.map +0 -1
- package/dist/components/Captcha.d.ts +0 -13
- package/dist/components/Captcha.d.ts.map +0 -1
- package/dist/components/Checkbox.d.ts +0 -12
- package/dist/components/Checkbox.d.ts.map +0 -1
- package/dist/components/DeletableInput.d.ts +0 -9
- package/dist/components/DeletableInput.d.ts.map +0 -1
- package/dist/components/FieldWrapper.d.ts +0 -20
- package/dist/components/FieldWrapper.d.ts.map +0 -1
- package/dist/components/FileInput.d.ts +0 -11
- package/dist/components/FileInput.d.ts.map +0 -1
- package/dist/components/Input.d.ts +0 -9
- package/dist/components/Input.d.ts.map +0 -1
- package/dist/components/NumberInput.d.ts +0 -14
- package/dist/components/NumberInput.d.ts.map +0 -1
- package/dist/components/Radio.d.ts +0 -14
- package/dist/components/Radio.d.ts.map +0 -1
- package/dist/components/Select.d.ts +0 -17
- package/dist/components/Select.d.ts.map +0 -1
- package/dist/components/Switchbox.d.ts +0 -11
- package/dist/components/Switchbox.d.ts.map +0 -1
- package/dist/components/Textarea.d.ts +0 -9
- package/dist/components/Textarea.d.ts.map +0 -1
- package/dist/components/ValidationError.d.ts +0 -17
- package/dist/components/ValidationError.d.ts.map +0 -1
- package/dist/components/types.d.ts +0 -11
- package/dist/components/types.d.ts.map +0 -1
- package/dist/da.js.map +0 -1
- package/dist/de.js.map +0 -1
- package/dist/en.js.map +0 -1
- package/dist/es.js.map +0 -1
- package/dist/fa.js.map +0 -1
- package/dist/form/Form.d.ts +0 -89
- package/dist/form/Form.d.ts.map +0 -1
- package/dist/form/FormContext.d.ts +0 -27
- package/dist/form/FormContext.d.ts.map +0 -1
- package/dist/fr.js.map +0 -1
- package/dist/gr.js.map +0 -1
- package/dist/hooks/useField.d.ts +0 -76
- package/dist/hooks/useField.d.ts.map +0 -1
- package/dist/hooks/useFieldStatesClassNames.d.ts +0 -4
- package/dist/hooks/useFieldStatesClassNames.d.ts.map +0 -1
- package/dist/hooks/useFieldValue.d.ts +0 -8
- package/dist/hooks/useFieldValue.d.ts.map +0 -1
- package/dist/hooks/useValidationClass.d.ts +0 -49
- package/dist/hooks/useValidationClass.d.ts.map +0 -1
- package/dist/hr.js.map +0 -1
- package/dist/hu.js.map +0 -1
- package/dist/it.js.map +0 -1
- package/dist/ja.js.map +0 -1
- package/dist/jp.js.map +0 -1
- package/dist/lang/es.d.ts +0 -32
- package/dist/lang/es.d.ts.map +0 -1
- package/dist/nl.js.map +0 -1
- package/dist/pl.js.map +0 -1
- package/dist/pt.js.map +0 -1
- package/dist/ro.js.map +0 -1
- package/dist/types.d.ts +0 -130
- package/dist/types.d.ts.map +0 -1
- package/dist/util.d.ts +0 -36
- package/dist/util.d.ts.map +0 -1
- package/dist/validationStore.d.ts +0 -112
- package/dist/validationStore.d.ts.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,26 +1,786 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import React__default, { ReactNode, FC } from 'react';
|
|
3
|
+
import { TModify, TPropsSelector, TPropsComparator, TPropsConfiguration, TId, EventEmitter } from '@apia/util';
|
|
4
|
+
import { TNumberInput, ApiaUtilModalHandler, TOpenModal } from '@apia/components';
|
|
5
|
+
import { BoxProps, ButtonProps, InputProps, RadioProps, SelectProps, SwitchProps, TextareaProps } from '@apia/theme';
|
|
6
|
+
|
|
7
|
+
declare const formcheckLanguage: {
|
|
8
|
+
required: string;
|
|
9
|
+
alpha: string;
|
|
10
|
+
alphanum: string;
|
|
11
|
+
nodigit: string;
|
|
12
|
+
digit: string;
|
|
13
|
+
digitmin: string;
|
|
14
|
+
digitltd: string;
|
|
15
|
+
number: string;
|
|
16
|
+
email: string;
|
|
17
|
+
image: string;
|
|
18
|
+
phone: string;
|
|
19
|
+
url: string;
|
|
20
|
+
confirm: string;
|
|
21
|
+
differs: string;
|
|
22
|
+
length_str: string;
|
|
23
|
+
length_fix: string;
|
|
24
|
+
lengthmax: string;
|
|
25
|
+
lengthmin: string;
|
|
26
|
+
words_min: string;
|
|
27
|
+
words_max: string;
|
|
28
|
+
words_range: string;
|
|
29
|
+
checkbox: string;
|
|
30
|
+
checkboxes_group: string;
|
|
31
|
+
radios: string;
|
|
32
|
+
select: string;
|
|
33
|
+
select_multiple: string;
|
|
34
|
+
errorsTitle: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
type TValidate = Partial<TModify<Record<keyof typeof formcheckLanguage, boolean>, {
|
|
38
|
+
digitmin: number;
|
|
39
|
+
digitltd: [number, number];
|
|
40
|
+
confirm: string;
|
|
41
|
+
differs: string;
|
|
42
|
+
length_str: [number, number];
|
|
43
|
+
length_fix: number;
|
|
44
|
+
words_min: number;
|
|
45
|
+
words_max: number;
|
|
46
|
+
words_range: [number, number];
|
|
47
|
+
checkboxes_group: number;
|
|
48
|
+
}> & {
|
|
49
|
+
patternMessage: string;
|
|
50
|
+
pattern: RegExp | string;
|
|
51
|
+
digitmax: number;
|
|
52
|
+
validName?: string;
|
|
53
|
+
maxLength: number;
|
|
54
|
+
minLength: number;
|
|
55
|
+
min: number;
|
|
56
|
+
max: number;
|
|
57
|
+
}>;
|
|
58
|
+
interface IFieldDefinition<ValueType = string> {
|
|
59
|
+
toolTip: string;
|
|
60
|
+
label: string;
|
|
61
|
+
name: string;
|
|
62
|
+
validate?: TValidate;
|
|
63
|
+
value: ValueType;
|
|
64
|
+
options?: {
|
|
65
|
+
label: string;
|
|
66
|
+
value: number | number;
|
|
67
|
+
selected?: boolean;
|
|
68
|
+
}[];
|
|
69
|
+
}
|
|
70
|
+
type TPromiseOrNot<Type> = Promise<Type> | Type;
|
|
71
|
+
type TSuccessfulValidation<ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> = {
|
|
72
|
+
values: ValueType;
|
|
73
|
+
submitValues: SubmitValueType;
|
|
74
|
+
};
|
|
75
|
+
type TWrongValidation = {
|
|
76
|
+
errors: Record<string, string>;
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Esta interfaz representa el resultado de la validación
|
|
80
|
+
* de un formulario.
|
|
81
|
+
*/
|
|
82
|
+
type TValidationResult<ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> = TSuccessfulValidation<ValueType, SubmitValueType> | TWrongValidation;
|
|
83
|
+
type TFieldValidationResult = true | string;
|
|
84
|
+
type TValidationFunction<ValueType> = (value: ValueType, formName: string) => TPromiseOrNot<TFieldValidationResult>;
|
|
85
|
+
type TValidationSubmitValueParser<ValueType = unknown, SubmitValueType = ValueType> = (value: ValueType) => SubmitValueType;
|
|
86
|
+
type TValidationValueParser<ValueType = unknown, ValidationValueType = unknown> = (value: ValueType) => ValidationValueType;
|
|
87
|
+
type TValidationRules = IFieldDefinition['validate'];
|
|
88
|
+
type TFocusRetriever = () => Promise<boolean> | void;
|
|
89
|
+
/**
|
|
90
|
+
* Esta interfaz representa el estado de un campo dentro
|
|
91
|
+
* del hook de validación.
|
|
92
|
+
*
|
|
93
|
+
* Las funcionalidades contempladas hasta el momento son:
|
|
94
|
+
*
|
|
95
|
+
* - Contener los valores del formulario.
|
|
96
|
+
* - Foco: Se hará querySelector sobre el form que lo contiene
|
|
97
|
+
* con el nombre provisto.
|
|
98
|
+
* - Función de validación o lista de reglas.
|
|
99
|
+
* - Manejo de errores.
|
|
100
|
+
* - Parsearlos para hacer submit.
|
|
101
|
+
*/
|
|
102
|
+
type TValidationField<ValueType = any, SubmitValueType = ValueType> = {
|
|
103
|
+
error?: string | null;
|
|
104
|
+
/**
|
|
105
|
+
* Permite definir una función personalizada para hacer foco sobre el campo. Se utiliza a la hora de validar el campo, cuando el mismo falla.
|
|
106
|
+
*/
|
|
107
|
+
focus?: TFocusRetriever;
|
|
108
|
+
isTouched: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* El nombre se utilizará para hacer foco en el campo en caso
|
|
111
|
+
* de que la validación del mismo fallara. Para ello se
|
|
112
|
+
* intenta recuperar un campo con el selector
|
|
113
|
+
* [name=${name}, #${name}], en caso de que el selector no
|
|
114
|
+
* encontrar ningún campo, se intentará hacer foco en el
|
|
115
|
+
* siguiente campo con error.
|
|
116
|
+
*/
|
|
117
|
+
name: string;
|
|
118
|
+
/**
|
|
119
|
+
* Como dice el nombre, es posible cambiar el nombre de un
|
|
120
|
+
* campo al hacer submit.
|
|
121
|
+
*/
|
|
122
|
+
submitName?: string;
|
|
123
|
+
/**
|
|
124
|
+
* Es posible recibir un valor ya parseado en el callback
|
|
125
|
+
* onValidate del Form, para ello se puede proveer este
|
|
126
|
+
* callback, que será llamado previo a llamar a onValidate.
|
|
127
|
+
*/
|
|
128
|
+
submitValueParser?: TValidationSubmitValueParser<ValueType, SubmitValueType | Promise<SubmitValueType> | undefined>;
|
|
129
|
+
/**
|
|
130
|
+
* Es posible pasar una función de validación personalizada
|
|
131
|
+
* para casos en los que la validación es significativamente
|
|
132
|
+
* compleja. En la mayoría de los casos debería bastar con
|
|
133
|
+
* la propiedad validationRules.
|
|
134
|
+
*/
|
|
135
|
+
validationFunction?: TValidationFunction<ValueType>;
|
|
136
|
+
/**
|
|
137
|
+
* Permite pasar una serie de reglas que el campo debe cumplir
|
|
138
|
+
* al validar.
|
|
139
|
+
*/
|
|
140
|
+
validationRules?: TValidationRules;
|
|
141
|
+
validationValueParser?: TValidationValueParser<ValueType>;
|
|
142
|
+
value: ValueType;
|
|
143
|
+
};
|
|
144
|
+
type TRegisterFormOptions = Partial<{
|
|
145
|
+
/**
|
|
146
|
+
* Si esta propiedad está seteada en true, el formulario se registrará y
|
|
147
|
+
* aquellos campos que ya tuvieran valor en el store no se volverán a
|
|
148
|
+
* registrar. En caso de que se incluyera initialValue, se hará updateValue de
|
|
149
|
+
* estos campos.
|
|
150
|
+
*/
|
|
151
|
+
avoidFieldsOverride: boolean;
|
|
152
|
+
initialValues: Record<string, unknown>;
|
|
153
|
+
/**
|
|
154
|
+
* Esta propiedad fuerza al formulario a guardarse en el localStorage. Adicionalmente,
|
|
155
|
+
* si al registrar el formulario ya existe información almacenada, la carga en el store
|
|
156
|
+
* e ignora las propiedades provistas en el método, a excepción de:
|
|
157
|
+
* - fields:validationFunction
|
|
158
|
+
* - fields:submitValueParser
|
|
159
|
+
*/
|
|
160
|
+
persistToSessionStorage: boolean;
|
|
161
|
+
}>;
|
|
162
|
+
type TUpdateFieldOptions = Partial<{
|
|
163
|
+
avoidPropagation?: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* Cuando se hace seteo de propiedades iniciales, se puede pasar este flag
|
|
166
|
+
* en false para que el formulario no aparezca como touched debido a estos
|
|
167
|
+
* cambios.
|
|
168
|
+
*/
|
|
169
|
+
markFormAsTouched: boolean;
|
|
170
|
+
}> & Pick<TRegisterFormOptions, 'avoidFieldsOverride'>;
|
|
171
|
+
type TRegisterFieldOptions = {
|
|
172
|
+
avoidPropagation?: boolean;
|
|
173
|
+
registerIfExists?: boolean;
|
|
174
|
+
};
|
|
175
|
+
type TRegisterField = Partial<TValidationField> & Pick<TValidationField, 'name'>;
|
|
176
|
+
type TFormState = {
|
|
177
|
+
fields: string[];
|
|
178
|
+
name: string;
|
|
179
|
+
isTouched: boolean;
|
|
180
|
+
isValid: boolean;
|
|
181
|
+
validationResult: TValidationResult<Record<string, unknown>> | null;
|
|
182
|
+
} & Pick<TRegisterFormOptions, 'avoidFieldsOverride' | 'persistToSessionStorage'>;
|
|
183
|
+
|
|
184
|
+
type TOnValidate<ValueType extends Record<string, unknown> = Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> = (validationResult: TValidationResult<ValueType, SubmitValueType>) => unknown;
|
|
185
|
+
interface IForm<ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> {
|
|
186
|
+
/**
|
|
187
|
+
* Si se pasa en true, los campos que se registren en este form no
|
|
188
|
+
* sobreescribirán valores previos si es que existen, sin importar el valor de
|
|
189
|
+
* avoidRegisterIfExists pasado al useField.
|
|
190
|
+
*/
|
|
191
|
+
avoidFieldsOverride?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Impide que se apliquen los estilos que indican que un campo fue alterado.
|
|
194
|
+
*/
|
|
195
|
+
avoidFieldsTouch?: boolean;
|
|
196
|
+
children: React__default.ReactNode;
|
|
197
|
+
className?: string;
|
|
198
|
+
initialValues?: Partial<ValueType>;
|
|
199
|
+
name?: string;
|
|
200
|
+
onUnmount?: () => unknown;
|
|
201
|
+
/**
|
|
202
|
+
* Cuando se ejecuta una acción de validación desde
|
|
203
|
+
* algún lugar de la aplicación se llama a este método
|
|
204
|
+
* con el resultado de dicha ejecución.
|
|
205
|
+
*/
|
|
206
|
+
onValidate?: TOnValidate<ValueType, SubmitValueType>;
|
|
207
|
+
persistToSessionStorage?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Permite definir si el formulario va a ser borrado de la validación al ser
|
|
210
|
+
* desmontado
|
|
211
|
+
*/
|
|
212
|
+
unregisterOnUnmount?: boolean;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Cuando se desea usar el sistema de validación,
|
|
216
|
+
* se debe utilizar este componente como form contenedor
|
|
217
|
+
* de todos los campos que quieran validarse.
|
|
218
|
+
*
|
|
219
|
+
* Es importante que no se coloquen formularios dentro
|
|
220
|
+
* de formularios ya que esto podría afectar negativamente
|
|
221
|
+
* el proceso de validación.
|
|
222
|
+
*
|
|
223
|
+
* @props
|
|
224
|
+
* *name:* Se puede pasar un nombre para identificar
|
|
225
|
+
* el form. Este nombre será utilizado para almacenar
|
|
226
|
+
* la información en Redux, por lo que si se desea
|
|
227
|
+
* acceder a la información recolectada por la librería,
|
|
228
|
+
* es conveniente pasar un nombre conocido y único. En
|
|
229
|
+
* caso de no se pase ningún nombre, la aplicación
|
|
230
|
+
* generará un nombre único automaticamente.
|
|
231
|
+
*
|
|
232
|
+
* *onValidate:* Un callback que será llamado cuando
|
|
233
|
+
* se invoque el método validateForm del store o cuando
|
|
234
|
+
* se lance el evento de submit del elemento form (por
|
|
235
|
+
* ejemplo mediante un click en un botón que no tenga
|
|
236
|
+
* type="button"), con el resultado de la validación.
|
|
237
|
+
*
|
|
238
|
+
* avoidFieldsOverride
|
|
239
|
+
* avoidFieldsTouch
|
|
240
|
+
*
|
|
241
|
+
* @see useField
|
|
242
|
+
* @see useForm
|
|
243
|
+
*
|
|
244
|
+
* @important Debido a que este hook renderiza un elemento
|
|
245
|
+
* form en el DOM, es importante agregar el atributo
|
|
246
|
+
* type="button" a todos los botones dentro del formulario
|
|
247
|
+
* que no se desea que disparen la validación.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* Para ver un ejemplo funcional, mira el componente
|
|
251
|
+
* Invitations.tsx
|
|
252
|
+
*
|
|
253
|
+
* // IMPORTANTE: El tipado del componente Form es genérico
|
|
254
|
+
* // por lo que es posible instanciarlo como se muestra a
|
|
255
|
+
* // continuación, lo que nos da el tipado correcto en el
|
|
256
|
+
* // callback onValidate.
|
|
257
|
+
* <Form<FormDataType> onValidate={(res) => {
|
|
258
|
+
* if(hasSucceedValidation(res)) {
|
|
259
|
+
* // Do something with submitValues
|
|
260
|
+
* } else {
|
|
261
|
+
* // Do something with errors
|
|
262
|
+
* }
|
|
263
|
+
* }}>
|
|
264
|
+
* ...{children}
|
|
265
|
+
* </Form>
|
|
266
|
+
*/
|
|
267
|
+
declare const Form: <ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>({ avoidFieldsOverride, avoidFieldsTouch, children, className, name, initialValues, onUnmount, onValidate, persistToSessionStorage, unregisterOnUnmount, }: IForm<ValueType, SubmitValueType>) => React__default.JSX.Element | null;
|
|
268
|
+
|
|
269
|
+
interface IFormContext<ValueType extends Record<string, unknown> = Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType> {
|
|
270
|
+
avoidFieldsTouch?: boolean;
|
|
271
|
+
name: string;
|
|
272
|
+
validate: () => Promise<TValidationResult<ValueType, SubmitValueType>>;
|
|
273
|
+
}
|
|
274
|
+
declare const FormContext: React__default.Context<IFormContext<Record<string, unknown>, Record<string, unknown>>>;
|
|
275
|
+
/**
|
|
276
|
+
* Provee acceso de forma sencilla al contexto de
|
|
277
|
+
* validación, que básicamente posee el nombre del
|
|
278
|
+
* form en caso de que se quiera usar para acceder
|
|
279
|
+
* a través de Redux a la información del mismo y un
|
|
280
|
+
* método validate, que dispara la validación del
|
|
281
|
+
* form.
|
|
282
|
+
*
|
|
283
|
+
* En la práctica, el método validate es casi
|
|
284
|
+
* innecesario, ya que la validación se puede disparar
|
|
285
|
+
* con cualquier botón que no tenga seteado el
|
|
286
|
+
* atributo type="button" (esto es así ya que en el
|
|
287
|
+
* DOM se renderiza un elemento de tipo form).
|
|
288
|
+
*/
|
|
289
|
+
declare function useFormContext(): IFormContext<Record<string, unknown>, Record<string, unknown>>;
|
|
290
|
+
|
|
291
|
+
declare global {
|
|
292
|
+
interface Window {
|
|
293
|
+
MSG_WRONG_VALIDATION_NO_FOCUSED_FILE: string;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
declare const validationsStore: {
|
|
297
|
+
activeForms: string[];
|
|
298
|
+
timeouts: Record<string, ReturnType<typeof setTimeout> | true>;
|
|
299
|
+
loadFromSessionStorage(formName: string): boolean;
|
|
300
|
+
persistFormToSessionStorage(formName: string): void;
|
|
301
|
+
getFieldStore(formName: string, fieldName: string): TValidationField;
|
|
302
|
+
getFormStore(formName: string): TFormState;
|
|
303
|
+
updateFieldStore(formName: string, fieldName: string, props: Partial<TValidationField>, noEmit?: boolean): void;
|
|
304
|
+
updateFormStore(formName: string, newState: Partial<TFormState>, avoidPersist?: boolean): void;
|
|
305
|
+
enableFormTouch(formName: string): void;
|
|
306
|
+
existsField: (formName: string, fieldName: string) => boolean;
|
|
307
|
+
makeFieldName(formName: string, fieldName: string): string;
|
|
308
|
+
makeFormName(formName: string): string;
|
|
309
|
+
registerField: (formName: string, registerData: TRegisterField, options?: TRegisterFieldOptions) => void;
|
|
310
|
+
/**
|
|
311
|
+
* Inicializa el estado de un nuevo formulario
|
|
312
|
+
*/
|
|
313
|
+
registerForm: (formName: string, props?: Partial<{
|
|
314
|
+
avoidFieldsOverride: boolean;
|
|
315
|
+
initialValues: Record<string, unknown>;
|
|
316
|
+
persistToSessionStorage: boolean;
|
|
317
|
+
}>) => void;
|
|
318
|
+
/**
|
|
319
|
+
* Setea el valor del campo con el nombre provisto. Si el campo no existe
|
|
320
|
+
* en el formulario lo crea.
|
|
321
|
+
*/
|
|
322
|
+
setFieldValue: (formName: string, fieldName: string, newValue: unknown, options?: TUpdateFieldOptions) => void;
|
|
323
|
+
setFormIsTouched: (formName: string, isTouched?: boolean) => void;
|
|
324
|
+
/**
|
|
325
|
+
* Elimina un campo del registro de validación de un formulario. De esta
|
|
326
|
+
* forma cualquier validación que pudiera aplicarse sobre el mismo, ya no se
|
|
327
|
+
* aplicará.
|
|
328
|
+
*/
|
|
329
|
+
unregisterField: (formName: string, fieldName: string) => void;
|
|
330
|
+
/**
|
|
331
|
+
* Elimina un formulario del store de validación junto con todos los campos
|
|
332
|
+
* asociados al mismo.
|
|
333
|
+
*/
|
|
334
|
+
unregisterForm: (formName: string) => void;
|
|
335
|
+
/**
|
|
336
|
+
* Actualiza las propiedades de un campo, si no existe, lo registra en el
|
|
337
|
+
* formulario.
|
|
338
|
+
*/
|
|
339
|
+
updateField: (formName: string, field: Partial<TValidationField> & Pick<TValidationField, 'name'>, options?: TUpdateFieldOptions) => void;
|
|
340
|
+
/**
|
|
341
|
+
* Actualiza múltiples campos al mismo tiempo.
|
|
342
|
+
*/
|
|
343
|
+
updateMultipleFields: (formName: string, fields: (Partial<TValidationField> & Pick<TValidationField, 'name'>)[], options?: TUpdateFieldOptions) => void;
|
|
344
|
+
/**
|
|
345
|
+
* Ejecuta la validación sobre un formulario. En caso de que la validación
|
|
346
|
+
* falle, se intenta hacer foco sobre el campo que no pudo validar.
|
|
347
|
+
* Es importante notar que en caso de que un campo requiera validación,
|
|
348
|
+
* debería estar presente en el DOM.
|
|
349
|
+
*
|
|
350
|
+
* No es necesario que el campo esté visible, ya que en caso de estar oculto
|
|
351
|
+
* (por ejemplo por ser hijo de un acordeón), se emitirá un evento para
|
|
352
|
+
* expandir al elemento padre que lo estuviera ocultando.
|
|
353
|
+
*
|
|
354
|
+
* @returns Devuelve una promesa que al ser resuelta otorga un objeto de tipo
|
|
355
|
+
* TValidationResult. Este tipo está pensado para ser usado en conjunto con
|
|
356
|
+
* el método hasSucceedFormValidation, que determinará si la validación fue
|
|
357
|
+
* exitosa o hubo errores.
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
*
|
|
361
|
+
* const result = await validationStore.validateForm('myForm');
|
|
362
|
+
* if(hasSucceedValidation(result)) {
|
|
363
|
+
* console.log('Success!', result);
|
|
364
|
+
* } else {
|
|
365
|
+
* console.error('Validation error', result);
|
|
366
|
+
* }
|
|
367
|
+
*/
|
|
368
|
+
validateForm: <ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>(formName: string) => Promise<TValidationResult<ValueType, SubmitValueType>>;
|
|
369
|
+
};
|
|
370
|
+
/**
|
|
371
|
+
* Este hook permite suscribirse a los cambios realizados en el
|
|
372
|
+
* store de validación de un formulario. Funciona igual a un
|
|
373
|
+
* useAppSelector en cuanto a la función selectora y comparadora.
|
|
374
|
+
*
|
|
375
|
+
* @param selector
|
|
376
|
+
* @param comparator
|
|
377
|
+
* @returns
|
|
378
|
+
*/
|
|
379
|
+
declare function useFormSelector<Selected = any>(formName: string, selector: TPropsSelector<Selected, TFormState>, comparator?: TPropsComparator<Selected>): Selected;
|
|
380
|
+
/**
|
|
381
|
+
* Este hook permite suscribirse a los cambios realizados en el
|
|
382
|
+
* store de validación de un campo de formulario. Funciona igual a un
|
|
383
|
+
* useAppSelector en cuanto a la función selectora y comparadora.
|
|
384
|
+
*
|
|
385
|
+
* @param selector
|
|
386
|
+
* @param comparator
|
|
387
|
+
* @returns
|
|
388
|
+
*/
|
|
389
|
+
declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, selector?: TPropsSelector<Selected, TValidationField<ValueType, SubmitValueType>>, comparator?: TPropsComparator<Selected>): Selected;
|
|
390
|
+
declare function useFieldSelector<ValueType = unknown, SubmitValueType = unknown, Selected = any>(formName: string, fieldName: string, configurator?: TPropsConfiguration<Selected, TValidationField<ValueType, SubmitValueType>>): Selected;
|
|
391
|
+
|
|
392
|
+
declare global {
|
|
393
|
+
interface Window {
|
|
394
|
+
NO_LANGUAGE_EXCEPTION: string;
|
|
395
|
+
MSG_INVALID_REG_EXP: string;
|
|
396
|
+
GNR_INVALID_NAME: string;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Determina si la validación de un campo resultó exitosa.
|
|
401
|
+
*/
|
|
402
|
+
declare function hasSucceedFieldValidation(result: TFieldValidationResult): result is true;
|
|
403
|
+
/**
|
|
404
|
+
* Determina si la validación de un formulario resultó
|
|
405
|
+
* exitosa. Está pensada para utilizar en el callback
|
|
406
|
+
* onValidate de Form o en la acción validationsActions.validateForm
|
|
407
|
+
*/
|
|
408
|
+
declare function hasSucceedFormValidation<ValueType extends Record<string, unknown>, SubmitValueType extends Record<keyof ValueType, unknown> = ValueType>(result: TValidationResult<ValueType, SubmitValueType>): result is TSuccessfulValidation<ValueType, SubmitValueType>;
|
|
409
|
+
/**
|
|
410
|
+
* Devuelve la cadena correspondiente a un código
|
|
411
|
+
* de error, realizando los reemplazos correspondientes.
|
|
412
|
+
*/
|
|
413
|
+
declare function lang(errorCode: keyof typeof formcheckLanguage, ...replacements: (string | number)[]): string;
|
|
414
|
+
declare function classToValidationFunction<T = string>(className: string): TValidationField<T>['validationFunction'];
|
|
415
|
+
declare function classToValidate(className: string): IFieldDefinition['validate'];
|
|
416
|
+
/**
|
|
417
|
+
* Realiza la carga de los mensajes de errores para el lenguaje
|
|
418
|
+
* especificado. Este método debe llamarse antes de utilizar
|
|
419
|
+
* las validaciones.
|
|
420
|
+
*/
|
|
421
|
+
declare function initValidations(): Promise<void>;
|
|
422
|
+
|
|
423
|
+
type TUseField<ValueType = unknown, SubmitValueType = ValueType> = Omit<TValidationField<ValueType, SubmitValueType>, 'error' | 'value' | 'isTouched'> & {
|
|
424
|
+
/**
|
|
425
|
+
* Con esta propiedad es posible evitar que el campo
|
|
426
|
+
* se registre cuando ya fue registrado previamente en
|
|
427
|
+
* el store. De esta forma, se evitaría escribir sobre
|
|
428
|
+
* un valor que ya estaba seteado anteriormente.
|
|
429
|
+
*/
|
|
430
|
+
avoidRegisterIfExists?: boolean;
|
|
431
|
+
/**
|
|
432
|
+
* Si se está fuera de contexto de validación, se puede pasar un formName
|
|
433
|
+
* para evitar que el hook lo intente tomar de contexto.
|
|
434
|
+
*/
|
|
435
|
+
formName?: string;
|
|
436
|
+
initialValue?: ValueType;
|
|
437
|
+
removeOnUnmount?: boolean;
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* Este hook permite registrar un field para ser validado,
|
|
441
|
+
* o simplemente para recolectar su valor, e incluso aplicar
|
|
442
|
+
* una función de transformación de dicho valor antes de
|
|
443
|
+
* hacer submit.
|
|
444
|
+
*
|
|
445
|
+
* @returns
|
|
446
|
+
* *error:* Es null mientras que no haya errores de
|
|
447
|
+
* validación, y un string en caso de que si lo haya.
|
|
448
|
+
*
|
|
449
|
+
* *value:* Es el valor actual del campo.
|
|
450
|
+
*
|
|
451
|
+
* *name:* Debería utilizarse para dar * valor al atributo
|
|
452
|
+
* name o id del contenedor que debe recibir el foco en caso
|
|
453
|
+
* de que la validación fallara. (Esto es, cuando se deba
|
|
454
|
+
* realizar foco porque la validación falló, la librería
|
|
455
|
+
* intentará encontrar un campo con el selector
|
|
456
|
+
* [name=${name}, #${name}] dentro del formulario).
|
|
457
|
+
*
|
|
458
|
+
* *onChange:* Se utiliza para setear el valor del campo,
|
|
459
|
+
* puede utilizarse directamente como callback para la
|
|
460
|
+
* propiedad onChange que aceptan la mayoría de los campos,
|
|
461
|
+
* ya que intentará setear el valor con ev.target.value
|
|
462
|
+
* y si esa propiedad no está definida, lo hará directamente
|
|
463
|
+
* con ev.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* // Si se desea un ejemplo más complejo, vea el componente
|
|
467
|
+
* // Invitations.tsx que se encuentra dentro del directorio
|
|
468
|
+
* // de la librería.
|
|
469
|
+
*
|
|
470
|
+
* const inputProps = useField<string>({
|
|
471
|
+
name: 'name',
|
|
472
|
+
validationRules: {
|
|
473
|
+
required: true,
|
|
474
|
+
minLength: 5,
|
|
475
|
+
maxLength: 10
|
|
476
|
+
},
|
|
477
|
+
initialValue: metadata.value,
|
|
478
|
+
* });
|
|
479
|
+
|
|
480
|
+
return <Box>
|
|
481
|
+
<Input {...inputProps} />
|
|
482
|
+
<ValidationError name="name" />
|
|
483
|
+
</Box>
|
|
484
|
+
*/
|
|
485
|
+
declare function useField<ValueType = unknown, SubmitValueType = ValueType>(fieldDefinition: TUseField<ValueType, SubmitValueType>): {
|
|
486
|
+
error: string | null | undefined;
|
|
487
|
+
isTouched: boolean;
|
|
488
|
+
name: string;
|
|
489
|
+
onChange: (ev: React__default.ChangeEvent | ValueType) => void;
|
|
490
|
+
updateValidations: ({ validationFunction, validationRules, }: Pick<TValidationField, 'validationRules' | 'validationFunction'>) => void;
|
|
491
|
+
value: ValueType;
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
declare global {
|
|
495
|
+
interface Window {
|
|
496
|
+
SHOW_REQUIRED_POSITION: string;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
interface IWrapper extends BoxProps {
|
|
500
|
+
avoidSemicolon?: boolean;
|
|
501
|
+
children: React__default.ReactNode;
|
|
502
|
+
label?: string;
|
|
503
|
+
name: string;
|
|
504
|
+
required?: boolean;
|
|
505
|
+
type?: 'checkbox';
|
|
506
|
+
}
|
|
507
|
+
declare const FieldWrapper: ({ name, label, avoidSemicolon, children, className, as, type, ...props }: IWrapper) => React__default.JSX.Element;
|
|
508
|
+
|
|
509
|
+
type TDefaultFieldType<ValueType = string> = Omit<TUseField<ValueType>, 'error' | 'value' | 'isTouched'> & {
|
|
510
|
+
label?: string;
|
|
511
|
+
initialValue?: ValueType;
|
|
512
|
+
validationClass?: string;
|
|
513
|
+
} & Pick<IWrapper, 'avoidSemicolon'>;
|
|
514
|
+
|
|
515
|
+
type TCaptchaProps = {
|
|
516
|
+
name: string;
|
|
517
|
+
imageUrl: string;
|
|
518
|
+
className?: string;
|
|
519
|
+
};
|
|
520
|
+
type TCaptcha = TCaptchaProps & Omit<TDefaultFieldType, 'validationFunction' | 'validationRules' | 'validationClass'>;
|
|
521
|
+
declare const InnerCaptcha: ({ className, name, imageUrl, avoidRegisterIfExists, avoidSemicolon, formName, label, removeOnUnmount, submitName, submitValueParser, validationValueParser, }: TCaptcha) => React__default.JSX.Element;
|
|
522
|
+
|
|
523
|
+
type TCheckboxProps = Omit<ButtonProps, 'onChange' | 'defaultChecked' | 'defaultValue'> & Pick<InputProps, 'onChange'>;
|
|
524
|
+
type TCheckbox = TCheckboxProps & TDefaultFieldType<boolean | string> & {
|
|
525
|
+
native?: boolean;
|
|
526
|
+
};
|
|
527
|
+
declare const Checkbox: React__default.ForwardRefExoticComponent<Omit<TCheckbox, "ref"> & React__default.RefAttributes<HTMLButtonElement>>;
|
|
528
|
+
|
|
529
|
+
type TDeletableInput = InputProps & TDefaultFieldType;
|
|
530
|
+
declare const DeletableInput: React__default.ForwardRefExoticComponent<Omit<TDeletableInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
|
|
531
|
+
|
|
532
|
+
type TFileInput = Omit<InputProps, 'onChange' | 'type' | 'value' | 'multiple'> & TDefaultFieldType<File | null> & Pick<TUseField, 'removeOnUnmount'> & Pick<IWrapper, 'avoidSemicolon'>;
|
|
533
|
+
declare const FileInput: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TFileInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
|
|
534
|
+
|
|
535
|
+
type TInput$1 = InputProps & TDefaultFieldType;
|
|
536
|
+
declare const Input: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TInput$1, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
|
|
537
|
+
|
|
538
|
+
declare global {
|
|
539
|
+
interface Window {
|
|
540
|
+
GNR_NUMERIC: string;
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
type TInput = TNumberInput & TDefaultFieldType;
|
|
544
|
+
declare const NumberInputf: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<Omit<TInput, "ref"> & React__default.RefAttributes<HTMLInputElement>>>;
|
|
545
|
+
|
|
546
|
+
type TRadio = RadioProps & TDefaultFieldType & {
|
|
547
|
+
options: {
|
|
548
|
+
value: string;
|
|
549
|
+
label: string;
|
|
550
|
+
}[];
|
|
551
|
+
};
|
|
552
|
+
declare const Radio: React__default.ForwardRefExoticComponent<Omit<TRadio, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
|
|
553
|
+
|
|
554
|
+
type TOption = {
|
|
555
|
+
value: TId;
|
|
556
|
+
label: string;
|
|
557
|
+
};
|
|
558
|
+
type TSelectProps = Omit<SelectProps, 'defaultValue'>;
|
|
559
|
+
type TSelect = TSelectProps & TDefaultFieldType & {
|
|
560
|
+
options: TOption[];
|
|
561
|
+
};
|
|
562
|
+
declare const Select: React__default.ForwardRefExoticComponent<Omit<TSelect, "ref"> & React__default.RefAttributes<HTMLSelectElement>>;
|
|
563
|
+
|
|
564
|
+
type TSwitchbox = Omit<SwitchProps, 'onChange'> & Pick<InputProps, 'onChange'> & TDefaultFieldType & {
|
|
565
|
+
reverse?: boolean;
|
|
566
|
+
};
|
|
567
|
+
declare const Switchbox: React__default.ForwardRefExoticComponent<Omit<TSwitchbox, "ref"> & React__default.RefAttributes<HTMLInputElement>>;
|
|
568
|
+
|
|
569
|
+
type TTextarea = TextareaProps & TDefaultFieldType;
|
|
570
|
+
declare const Textarea: React__default.ForwardRefExoticComponent<Omit<TTextarea, "ref"> & React__default.RefAttributes<HTMLTextAreaElement>>;
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Renderiza los errores del campo con el nombre pasado
|
|
574
|
+
* como prop. En caso de que no exista error, no renderiza
|
|
575
|
+
* nada.
|
|
576
|
+
*
|
|
577
|
+
* @props
|
|
578
|
+
* *name:* El nombre del campo cuyos errores se quieren
|
|
579
|
+
* renderizar.
|
|
580
|
+
*/
|
|
581
|
+
declare const ValidationError: ({ name }: {
|
|
582
|
+
name: string;
|
|
583
|
+
}) => React.JSX.Element | null;
|
|
584
|
+
|
|
585
|
+
declare abstract class CollectorField<ValueType = any, FieldProps = any> extends EventEmitter<{
|
|
586
|
+
focusFunctionUpdate: TFocusRetriever;
|
|
587
|
+
functionUpdate: TValidationFunction<ValueType>;
|
|
588
|
+
optionsUpdate: TOption[];
|
|
589
|
+
propsUpdate: Partial<FieldProps>;
|
|
590
|
+
rulesUpdate: TValidationRules;
|
|
591
|
+
}> {
|
|
592
|
+
#private;
|
|
593
|
+
readonly name: string;
|
|
594
|
+
protected label: ReactNode;
|
|
595
|
+
/**
|
|
596
|
+
* Este es el componente de implementación de cada campo particular
|
|
597
|
+
*/
|
|
598
|
+
abstract Component: FC;
|
|
599
|
+
abstract type: string;
|
|
600
|
+
constructor(name: string, label: ReactNode, properties?: Partial<FieldProps>);
|
|
601
|
+
collector: Collector;
|
|
602
|
+
isHidden: () => boolean;
|
|
603
|
+
setIsHidden: (isHidden: boolean) => void;
|
|
604
|
+
protected properties: Partial<FieldProps>;
|
|
605
|
+
setProperties: (newProps: Partial<FieldProps>) => void;
|
|
606
|
+
protected useProperties: () => Partial<FieldProps>;
|
|
607
|
+
/**
|
|
608
|
+
* Este componente se utiliza para controlar propiedades comunes a todos los
|
|
609
|
+
* campos.
|
|
610
|
+
*/
|
|
611
|
+
SuperComponent: () => React.JSX.Element | null;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
declare abstract class ValidatedCollectorField<ValueType = any, FieldProps = any> extends CollectorField<ValueType, FieldProps> {
|
|
615
|
+
readonly name: string;
|
|
616
|
+
protected label: string;
|
|
617
|
+
protected config: Partial<{
|
|
618
|
+
initialValue: ValueType;
|
|
619
|
+
properties: Partial<FieldProps>;
|
|
620
|
+
validationFunction: TValidationFunction<ValueType>;
|
|
621
|
+
validationRules: TValidationRules;
|
|
622
|
+
}>;
|
|
623
|
+
constructor(name: string, label: string, config?: Partial<{
|
|
624
|
+
initialValue: ValueType;
|
|
625
|
+
properties: Partial<FieldProps>;
|
|
626
|
+
validationFunction: TValidationFunction<ValueType>;
|
|
627
|
+
validationRules: TValidationRules;
|
|
628
|
+
}>);
|
|
629
|
+
get initialValue(): ValueType | undefined;
|
|
630
|
+
setInitialValue: (newValue: ValueType) => void;
|
|
631
|
+
setValidationFunction: (newFunction: TValidationFunction<ValueType>) => void;
|
|
632
|
+
setValidationRules: (newRules: TValidationRules) => void;
|
|
633
|
+
setValue: (newValue: ValueType) => void;
|
|
634
|
+
protected useValidationFunction: () => TValidationFunction<ValueType> | undefined;
|
|
635
|
+
protected useValidationRules: () => Partial<Omit<Record<"number" | "required" | "alpha" | "alphanum" | "nodigit" | "digit" | "digitmin" | "digitltd" | "email" | "image" | "phone" | "url" | "confirm" | "differs" | "length_str" | "length_fix" | "lengthmax" | "lengthmin" | "words_min" | "words_max" | "words_range" | "checkbox" | "checkboxes_group" | "radios" | "select" | "select_multiple" | "errorsTitle", boolean>, "digitmin" | "digitltd" | "confirm" | "differs" | "length_str" | "length_fix" | "words_min" | "words_max" | "words_range" | "checkboxes_group"> & {
|
|
636
|
+
digitmin: number;
|
|
637
|
+
digitltd: [number, number];
|
|
638
|
+
confirm: string;
|
|
639
|
+
differs: string;
|
|
640
|
+
length_str: [number, number];
|
|
641
|
+
length_fix: number;
|
|
642
|
+
words_min: number;
|
|
643
|
+
words_max: number;
|
|
644
|
+
words_range: [number, number];
|
|
645
|
+
checkboxes_group: number;
|
|
646
|
+
} & {
|
|
647
|
+
patternMessage: string;
|
|
648
|
+
pattern: string | RegExp;
|
|
649
|
+
digitmax: number;
|
|
650
|
+
validName?: string | undefined;
|
|
651
|
+
maxLength: number;
|
|
652
|
+
minLength: number;
|
|
653
|
+
min: number;
|
|
654
|
+
max: number;
|
|
655
|
+
}> | undefined;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
declare class CollectorCheckbox extends ValidatedCollectorField<string | boolean, Omit<TCheckboxProps, 'name'>> {
|
|
659
|
+
type: string;
|
|
660
|
+
Component: () => React.JSX.Element;
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
declare class CollectorInput extends ValidatedCollectorField<string, Omit<InputProps, 'name'>> {
|
|
664
|
+
type: string;
|
|
665
|
+
Component: () => React.JSX.Element;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
declare class CollectorSelect extends ValidatedCollectorField<string, Omit<TSelectProps, 'name'>> {
|
|
669
|
+
#private;
|
|
670
|
+
protected _name: string;
|
|
671
|
+
protected label: string;
|
|
672
|
+
type: string;
|
|
673
|
+
constructor(_name: string, label: string, config?: Partial<{
|
|
674
|
+
initialValue: string;
|
|
675
|
+
options: TOption[];
|
|
676
|
+
properties: Partial<Omit<TSelectProps, 'name'>>;
|
|
677
|
+
validationFunction: TValidationFunction<string>;
|
|
678
|
+
validationRules: TValidationRules;
|
|
679
|
+
}>);
|
|
680
|
+
addOption: (newOption: TOption) => void;
|
|
681
|
+
setOptions: (newOptions: TOption[]) => void;
|
|
682
|
+
Component: () => React.JSX.Element;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
declare class CollectorTextarea extends ValidatedCollectorField<string, Omit<TextareaProps, 'name'>> {
|
|
686
|
+
type: string;
|
|
687
|
+
Component: () => React.JSX.Element;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
declare class CollectorLabel extends CollectorField {
|
|
691
|
+
private kind;
|
|
692
|
+
private static maxId;
|
|
693
|
+
type: string;
|
|
694
|
+
constructor(label: ReactNode, kind?: 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'p' | 'label');
|
|
695
|
+
Component: () => React.JSX.Element;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
declare class CollectorButton extends CollectorField<null, Omit<ButtonProps, 'children'>> {
|
|
699
|
+
protected label: string;
|
|
700
|
+
type: string;
|
|
701
|
+
constructor(label: string, properties?: Omit<ButtonProps, 'children'>);
|
|
702
|
+
Component: () => React.JSX.Element;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
declare class Collector {
|
|
706
|
+
#private;
|
|
707
|
+
fields: {
|
|
708
|
+
button: typeof CollectorButton;
|
|
709
|
+
checkbox: typeof CollectorCheckbox;
|
|
710
|
+
input: typeof CollectorInput;
|
|
711
|
+
/**
|
|
712
|
+
* Muestra una etiqueta con tag personalizable: h1...h6, p, label. (Por
|
|
713
|
+
* defecto: label)
|
|
714
|
+
*/
|
|
715
|
+
label: typeof CollectorLabel;
|
|
716
|
+
select: typeof CollectorSelect;
|
|
717
|
+
textarea: typeof CollectorTextarea;
|
|
718
|
+
};
|
|
719
|
+
private private__id;
|
|
720
|
+
get id(): string;
|
|
721
|
+
modal: ApiaUtilModalHandler | null;
|
|
722
|
+
add: (...fields: CollectorField[]) => this;
|
|
723
|
+
forEach: (cb: (field: CollectorField, i: number) => void) => void;
|
|
724
|
+
show: <FormValues extends Record<string, unknown>>(modalProps?: (Partial<Omit<TOpenModal, "children" | "onConfirm" | "onCancel" | "confirmProps">> & Partial<{
|
|
725
|
+
hideConfirm: boolean;
|
|
726
|
+
/**
|
|
727
|
+
* Si este método devuelve false, el modal no se cerrará
|
|
728
|
+
*/
|
|
729
|
+
onConfirm?: ((res: FormValues | null) => boolean) | undefined;
|
|
730
|
+
}>) | undefined) => Promise<FormValues | null>;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
declare function useFieldStatesClassNames<T = unknown>(name: string, formName?: string): string;
|
|
734
|
+
|
|
735
|
+
interface IUseFieldValue {
|
|
736
|
+
formName?: string;
|
|
737
|
+
name: string;
|
|
738
|
+
}
|
|
739
|
+
declare function useFieldValue<T = unknown>({ formName, name }: IUseFieldValue): T;
|
|
740
|
+
|
|
741
|
+
declare function useValidationClass<T>({ customValidation, formName, name, validationClass, validationFunction, validationRules, }: Pick<TDefaultFieldType<T>, 'validationClass' | 'validationFunction' | 'validationRules' | 'name'> & {
|
|
742
|
+
customValidation?: TValidationFunction<T>;
|
|
743
|
+
formName?: string;
|
|
744
|
+
}): {
|
|
745
|
+
actualValidationFunction: TValidationFunction<T>;
|
|
746
|
+
actualValidationRules: {
|
|
747
|
+
number?: boolean | undefined;
|
|
748
|
+
required?: boolean | undefined;
|
|
749
|
+
alpha?: boolean | undefined;
|
|
750
|
+
alphanum?: boolean | undefined;
|
|
751
|
+
nodigit?: boolean | undefined;
|
|
752
|
+
digit?: boolean | undefined;
|
|
753
|
+
email?: boolean | undefined;
|
|
754
|
+
image?: boolean | undefined;
|
|
755
|
+
phone?: boolean | undefined;
|
|
756
|
+
url?: boolean | undefined;
|
|
757
|
+
lengthmax?: boolean | undefined;
|
|
758
|
+
lengthmin?: boolean | undefined;
|
|
759
|
+
checkbox?: boolean | undefined;
|
|
760
|
+
radios?: boolean | undefined;
|
|
761
|
+
select?: boolean | undefined;
|
|
762
|
+
select_multiple?: boolean | undefined;
|
|
763
|
+
errorsTitle?: boolean | undefined;
|
|
764
|
+
digitmin?: number | undefined;
|
|
765
|
+
digitltd?: [number, number] | undefined;
|
|
766
|
+
confirm?: string | undefined;
|
|
767
|
+
differs?: string | undefined;
|
|
768
|
+
length_str?: [number, number] | undefined;
|
|
769
|
+
length_fix?: number | undefined;
|
|
770
|
+
words_min?: number | undefined;
|
|
771
|
+
words_max?: number | undefined;
|
|
772
|
+
words_range?: [number, number] | undefined;
|
|
773
|
+
checkboxes_group?: number | undefined;
|
|
774
|
+
patternMessage?: string | undefined;
|
|
775
|
+
pattern?: string | RegExp | undefined;
|
|
776
|
+
digitmax?: number | undefined;
|
|
777
|
+
validName?: string | undefined;
|
|
778
|
+
maxLength?: number | undefined;
|
|
779
|
+
minLength?: number | undefined;
|
|
780
|
+
min?: number | undefined;
|
|
781
|
+
max?: number | undefined;
|
|
782
|
+
};
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
export { InnerCaptcha as Captcha, Checkbox, Collector, CollectorField, DeletableInput, FieldWrapper, FileInput, Form, FormContext, type IWrapper, Input, NumberInputf, Radio, Select, Switchbox, type TCheckbox, type TCheckboxProps, type TDefaultFieldType, type TInput$1 as TInput, type TOnValidate, type TOption, type TRadio, type TSelect, type TSelectProps, type TSwitchbox, type TUseField, type TValidationFunction, type TValidationResult, type TValidationRules, Textarea, ValidatedCollectorField, ValidationError, classToValidate, classToValidationFunction, hasSucceedFieldValidation, hasSucceedFormValidation, initValidations, lang, useField, useFieldSelector, useFieldStatesClassNames, useFieldValue, useFormContext, useFormSelector, useValidationClass, validationsStore };
|
|
26
786
|
//# sourceMappingURL=index.d.ts.map
|