Skip to content

Commit 6e22100

Browse files
committed
fix(Form): add deprecation warnings for createField and removeField
1 parent 746c7dd commit 6e22100

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/components/form/Form/use-form.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,21 @@ export class CubeFormInstance<
341341
return Object.values(this.fields).some((field) => field?.touched);
342342
}
343343

344-
// True if all fields are verified and valid
345-
// @IMPORTANT: This is not the same as `!isInvalid`, because it also checks if all fields are verified
344+
/**
345+
* True if all fields are verified and valid
346+
* IMPORTANT: This is not the same as `!isInvalid`, because it also checks if all fields are verified.
347+
*/
346348
get isValid(): boolean {
347349
return Object.values(this.fields).every((field) => {
348350
return field?.status === 'valid';
349351
});
350352
}
351353

352-
// True if at least one field is verified and invalid
354+
/**
355+
* True if at least one field is verified and invalid.
356+
* IMPORTANT: This is not the same as `!isValid`, because it only checks that at least
357+
* one field is verified and invalid.
358+
*/
353359
get isInvalid(): boolean {
354360
return Object.values(this.fields).some((field) => {
355361
return field?.status === 'invalid';
@@ -364,6 +370,9 @@ export class CubeFormInstance<
364370
return field.errors || [];
365371
}
366372

373+
/**
374+
* @deprecated This field is not supposed to be used directly.
375+
*/
367376
createField<Name extends keyof T & string>(name: Name, skipRender?: boolean) {
368377
// passing an empty name is incorrect, but we have to return a valid object to avoid inconsistency
369378
if (!name) {
@@ -381,6 +390,9 @@ export class CubeFormInstance<
381390
return this.fields[name];
382391
}
383392

393+
/**
394+
* @deprecated This field is not supposed to be used directly.
395+
*/
384396
removeField<Name extends keyof T & string>(name: Name, skipRender?: boolean) {
385397
if (this.fields[name]) {
386398
delete this.fields[name];
@@ -393,8 +405,10 @@ export class CubeFormInstance<
393405

394406
/**
395407
* @deprecated This method is not recommended. Use other ways to alter fields.
396-
* You can use `setFieldValue` to change the value of a field.
397-
* You can use `verifyField` to validate a field.
408+
* Use `setFieldValue` to change the value of a field.
409+
* Use `verifyField` to validate a field.
410+
* Use `setFieldError` to set an error for a field.
411+
* Use `clearFieldsValidation` to clear all errors for a field.
398412
*/
399413
setFields<Names extends keyof T & string>(
400414
newFields: SetFieldsArrType<T, Names>[],

0 commit comments

Comments
 (0)