Skip to content

How do I verify that the value of a rule is null #242

Answered by jakeboone02
Andy-lm asked this question in Q&A
Discussion options

You must be logged in to vote

There are a couple of things you can do to remove "invalid" rules.

formatQuery using a validator method

If you're using the formatQuery method to send a WHERE clause directly to the server, then you can add a validation function to remove invalid rules (or groups). Something like this:

import { formatQuery } from 'react-querybuilder';

const validator = (query) => {
  const result = {};

  const validateRule = (rule) => {
    if (!rule.value) {
      result[rule.id] = false;
    }
  };

  const validateGroup = (rg) => {
    const reasons = [];
    if (rg.rules.length === 0) {
      reasons.push("empty");
    }
    if (rg.id) {
      if (reasons.length) {
        result[rg.id] = { valid: f…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Andy-lm
Comment options

@jakeboone02
Comment options

Answer selected by Andy-lm
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