@ttoss/forms 0.32.3 → 0.32.4
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/README.md
CHANGED
|
@@ -85,11 +85,21 @@ const MyForm = () => {
|
|
|
85
85
|
|
|
86
86
|
### Validation Messages
|
|
87
87
|
|
|
88
|
-
Invalid fields display default error messages like "Field is required".
|
|
88
|
+
Invalid fields display default error messages like "Field is required". These messages are defined using i18n and can be customized for each locale.
|
|
89
89
|
|
|
90
|
-
|
|
90
|
+
#### Default Yup Messages
|
|
91
91
|
|
|
92
|
-
|
|
92
|
+
The package provides internationalized default messages for common Yup validation errors. These are automatically extracted when you run `pnpm run i18n`:
|
|
93
|
+
|
|
94
|
+
- **Required field**: "Field is required"
|
|
95
|
+
- **Type mismatch**: "Invalid Value for Field of type {type}"
|
|
96
|
+
- **Minimum length**: "Field must be at least {min} characters"
|
|
97
|
+
|
|
98
|
+
To customize these messages for your locale, extract the i18n messages and translate them in your application's i18n files (e.g., `i18n/compiled/pt-BR.json`). See the [i18n-CLI documentation](https://ttoss.dev/docs/modules/packages/i18n-cli/) for more details.
|
|
99
|
+
|
|
100
|
+
#### Custom Schema Messages
|
|
101
|
+
|
|
102
|
+
You can also provide custom error messages directly in your Yup schemas using i18n patterns:
|
|
93
103
|
|
|
94
104
|
```tsx
|
|
95
105
|
import { useI18n } from '@ttoss/react-i18n';
|
|
@@ -431,17 +441,30 @@ Numeric input with formatting support (decimals, thousands separators).
|
|
|
431
441
|
|
|
432
442
|
### FormFieldCurrencyInput
|
|
433
443
|
|
|
434
|
-
Currency input with locale-based formatting.
|
|
444
|
+
Currency input with locale-based formatting. The decimal and thousand separators are automatically determined by the locale set in the `I18nProvider`.
|
|
435
445
|
|
|
436
446
|
```tsx
|
|
437
|
-
<FormFieldCurrencyInput
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
447
|
+
<FormFieldCurrencyInput name="amount" label="Amount" prefix="$" />
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
#### Customizing Separators per Locale
|
|
451
|
+
|
|
452
|
+
The component uses i18n messages to determine the decimal and thousand separators based on the current locale. You can customize these for each locale in your application:
|
|
453
|
+
|
|
454
|
+
1. First, extract the i18n messages by running `pnpm run i18n` in your package
|
|
455
|
+
2. In your application's i18n files (e.g., `i18n/compiled/pt-BR.json`), add the custom separators:
|
|
456
|
+
|
|
457
|
+
```json
|
|
458
|
+
{
|
|
459
|
+
"JnCaDG": ",", // Decimal separator (default: ".")
|
|
460
|
+
"0+4wTp": "." // Thousand separator (default: ",")
|
|
461
|
+
}
|
|
443
462
|
```
|
|
444
463
|
|
|
464
|
+
This approach allows each locale to define its own number formatting rules, which will be automatically applied to all currency inputs.
|
|
465
|
+
|
|
466
|
+
For more information about the i18n workflow, see the [i18n-CLI documentation](https://ttoss.dev/docs/modules/packages/i18n-cli/).
|
|
467
|
+
|
|
445
468
|
### FormFieldPatternFormat
|
|
446
469
|
|
|
447
470
|
Input with custom format patterns.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { Form, useForm, yupResolver } from "../chunk-
|
|
3
|
+
import { Form, useForm, yupResolver } from "../chunk-L2FEA5RZ.js";
|
|
4
4
|
import { __name } from "../chunk-A5YD5USY.js";
|
|
5
5
|
|
|
6
6
|
// src/MultistepForm/MultistepForm.tsx
|
|
@@ -80,6 +80,9 @@ var FormFieldCreditCardNumber = /* @__PURE__ */__name(({
|
|
|
80
80
|
});
|
|
81
81
|
}, "FormFieldCreditCardNumber");
|
|
82
82
|
|
|
83
|
+
// src/FormFieldCurrencyInput.tsx
|
|
84
|
+
import { defineMessages, useI18n } from "@ttoss/react-i18n";
|
|
85
|
+
|
|
83
86
|
// src/FormFieldNumericFormat.tsx
|
|
84
87
|
import { Input } from "@ttoss/ui";
|
|
85
88
|
import { NumericFormat } from "react-number-format";
|
|
@@ -131,19 +134,40 @@ var FormFieldNumericFormat = /* @__PURE__ */__name(({
|
|
|
131
134
|
}, "FormFieldNumericFormat");
|
|
132
135
|
|
|
133
136
|
// src/FormFieldCurrencyInput.tsx
|
|
137
|
+
var messages = defineMessages({
|
|
138
|
+
decimalSeparator: {
|
|
139
|
+
id: "JnCaDG",
|
|
140
|
+
defaultMessage: [{
|
|
141
|
+
"type": 0,
|
|
142
|
+
"value": "."
|
|
143
|
+
}]
|
|
144
|
+
},
|
|
145
|
+
thousandSeparator: {
|
|
146
|
+
id: "0+4wTp",
|
|
147
|
+
defaultMessage: [{
|
|
148
|
+
"type": 0,
|
|
149
|
+
"value": ","
|
|
150
|
+
}]
|
|
151
|
+
}
|
|
152
|
+
});
|
|
134
153
|
var FormFieldCurrencyInput = /* @__PURE__ */__name(({
|
|
135
154
|
prefix,
|
|
136
|
-
decimalSeparator
|
|
137
|
-
thousandSeparator
|
|
155
|
+
decimalSeparator,
|
|
156
|
+
thousandSeparator,
|
|
138
157
|
...formFieldNumericFormatProps
|
|
139
158
|
}) => {
|
|
159
|
+
const {
|
|
160
|
+
intl
|
|
161
|
+
} = useI18n();
|
|
162
|
+
const finalDecimalSeparator = decimalSeparator ?? intl.formatMessage(messages.decimalSeparator);
|
|
163
|
+
const finalThousandSeparator = thousandSeparator ?? intl.formatMessage(messages.thousandSeparator);
|
|
140
164
|
return /* @__PURE__ */React.createElement(FormFieldNumericFormat, {
|
|
141
165
|
fixedDecimalScale: true,
|
|
142
166
|
decimalScale: 2,
|
|
143
167
|
prefix,
|
|
144
|
-
decimalSeparator,
|
|
145
|
-
thousandSeparator,
|
|
146
|
-
placeholder: `${prefix} 0${
|
|
168
|
+
decimalSeparator: finalDecimalSeparator,
|
|
169
|
+
thousandSeparator: finalThousandSeparator,
|
|
170
|
+
placeholder: `${prefix} 0${finalDecimalSeparator}00`,
|
|
147
171
|
allowNegative: false,
|
|
148
172
|
...formFieldNumericFormatProps
|
|
149
173
|
});
|
package/dist/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/** Powered by @ttoss/config. https://ttoss.dev/docs/modules/packages/config/ */
|
|
2
|
-
import { Controller, Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-
|
|
2
|
+
import { Controller, Form, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver } from "./chunk-L2FEA5RZ.js";
|
|
3
3
|
import { FormErrorMessage, FormField, FormFieldPatternFormat } from "./chunk-A5YD5USY.js";
|
|
4
4
|
export { Controller, Form, FormErrorMessage, FormField, FormFieldCheckbox, FormFieldCreditCardNumber, FormFieldCurrencyInput, FormFieldInput, FormFieldNumericFormat, FormFieldPassword, FormFieldPatternFormat, FormFieldRadio, FormFieldRadioCard, FormFieldRadioCardIcony, FormFieldSelect, FormFieldSwitch, FormFieldTextarea, FormGroup, FormProvider, useController, useFieldArray, useForm, useFormContext, useFormGroup, useFormState, useWatch, yup, yupResolver };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ttoss/forms",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "ttoss",
|
|
6
6
|
"contributors": [
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"react": ">=16.8.0",
|
|
42
|
-
"@ttoss/
|
|
43
|
-
"@ttoss/
|
|
42
|
+
"@ttoss/react-i18n": "^2.0.21",
|
|
43
|
+
"@ttoss/ui": "^5.10.7"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/jest": "^30.0.0",
|
|
@@ -51,11 +51,11 @@
|
|
|
51
51
|
"tsup": "^8.5.1",
|
|
52
52
|
"yup": "^1.7.1",
|
|
53
53
|
"@ttoss/config": "^1.35.11",
|
|
54
|
-
"@ttoss/
|
|
54
|
+
"@ttoss/react-icons": "^0.5.2",
|
|
55
55
|
"@ttoss/test-utils": "^3.0.3",
|
|
56
56
|
"@ttoss/ui": "^5.10.7",
|
|
57
|
-
"@ttoss/react-
|
|
58
|
-
"@ttoss/
|
|
57
|
+
"@ttoss/react-i18n": "^2.0.21",
|
|
58
|
+
"@ttoss/i18n-cli": "^0.7.37"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public",
|