fix: skip field validation when fields are hidden
This commit is contained in:
parent
61621a9759
commit
618a65deec
@ -1,6 +1,7 @@
|
|||||||
import { Schema, useFieldSchema } from '@formily/react';
|
import { Field } from '@formily/core';
|
||||||
|
import { Schema, useField, useFieldSchema } from '@formily/react';
|
||||||
import { Spin } from 'antd';
|
import { Spin } from 'antd';
|
||||||
import React, { createContext, useContext } from 'react';
|
import React, { createContext, useContext, useEffect } from 'react';
|
||||||
import { Redirect } from 'react-router-dom';
|
import { Redirect } from 'react-router-dom';
|
||||||
import { useAPIClient, useRequest } from '../api-client';
|
import { useAPIClient, useRequest } from '../api-client';
|
||||||
import { useBlockRequestContext } from '../block-provider/BlockProvider';
|
import { useBlockRequestContext } from '../block-provider/BlockProvider';
|
||||||
@ -251,6 +252,7 @@ export const useACLFieldWhitelist = () => {
|
|||||||
|
|
||||||
export const ACLCollectionFieldProvider = (props) => {
|
export const ACLCollectionFieldProvider = (props) => {
|
||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
|
const field = useField<Field>();
|
||||||
const { allowAll } = useACLRoleContext();
|
const { allowAll } = useACLRoleContext();
|
||||||
if (allowAll) {
|
if (allowAll) {
|
||||||
return <>{props.children}</>;
|
return <>{props.children}</>;
|
||||||
@ -260,6 +262,12 @@ export const ACLCollectionFieldProvider = (props) => {
|
|||||||
}
|
}
|
||||||
const { whitelist } = useACLFieldWhitelist();
|
const { whitelist } = useACLFieldWhitelist();
|
||||||
const allowed = whitelist.length > 0 ? whitelist.includes(fieldSchema.name) : true;
|
const allowed = whitelist.length > 0 ? whitelist.includes(fieldSchema.name) : true;
|
||||||
|
useEffect(() => {
|
||||||
|
if (!allowed) {
|
||||||
|
field.required = false;
|
||||||
|
field.display = 'hidden';
|
||||||
|
}
|
||||||
|
}, [allowed]);
|
||||||
if (!allowed) {
|
if (!allowed) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user