Skip to content

can we restrict not toggle option to a single level rule? #626

Answered by jakeboone02
kuljeet2604 asked this question in Q&A
Discussion options

You must be logged in to vote

You can achieve this with a custom RuleGroup component:

https://codesandbox.io/p/devbox/infallible-star-h8v3td?file=%2Fsrc%2FApp.tsx%3A19%2C1-32%2C1

const CustomRuleGroup = (props: RuleGroupProps) => {
  if (props.context?.parentHasNotTrue) {
    return (
      <RuleGroup
        {...props}
        schema={{ ...props.schema, showNotToggle: false }}
      />
    );
  } else if (props.ruleGroup.not) {
    return <RuleGroup {...props} context={{ parentHasNotTrue: true }} />;
  }
  return <RuleGroup {...props} />;
};

export const App = () => {
  const [query, setQuery] = useState(initialQuery);

  return (
    <QueryBuilder
      fields={fields}
      query={query}
      onQueryChange={setQuery

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@kuljeet2604
Comment options

Answer selected by kuljeet2604
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants