Requiring Values

Making sure required fields contain a real value.

Requiring values means rejecting rows where a mandatory field is empty. The hard part is defining empty: a cell with only spaces or the text N/A is effectively missing, while 0 and false are real values that a careless check rejects.

Why it matters when importing data

Required fields are the first line of defense against incomplete records, such as a product with no SKU or an employee with no start date. Checking them on import, with clear messages, stops incomplete data at the door instead of after it breaks something downstream.

Requiring Values in JavaScript

A truthy check such as if (!value) treats 0 and false as missing. Check for null, undefined, blanks, and placeholder text explicitly instead:

// Values that mean "nothing was entered", even though the cell is not empty.
const PLACEHOLDERS = new Set(["", "n/a", "na", "null", "none", "-", "--", "?"]);

const isMissing = (value) =>
  value === null ||
  value === undefined ||
  PLACEHOLDERS.has(String(value).trim().toLowerCase());

const required = ["sku", "price", "inStock"];

const rows = [
  { sku: "A-100", price: 0, inStock: false },
  { sku: " ", price: 19.99, inStock: true },
  { sku: "A-102", price: "N/A", inStock: true },
  { sku: "A-103", price: 5, inStock: undefined },
];

const results = rows.map((row, index) => ({
  row: index + 1,
  missing:
    required.filter((field) => isMissing(row[field])).join(", ") || "none",
  naiveCheck: required.filter((field) => !row[field]).join(", ") || "none",
}));
console.table(results);

Input

skupriceinStock
A-1000false
(spaces only)19.99true
A-102N/Atrue
A-1035(missing)

Output

RowMissing (correct check)Missing (!value check)
1noneprice, inStock
2skunone
3pricenone
4inStockinStock

Edge cases to handle

  • Zero and false. A price of 0 or an inStock of false is a real answer. Never use a truthy check for required fields.
  • Placeholders. N/A, null, -, and none typed into a cell usually mean nothing was entered. But NA is also Namibia's country code and None can be a real answer, so decide the placeholder list per field.
  • Conditionally required. Some fields are required only when another is filled in, such as state when country is US.
  • Required column versus required value. A column can be present with some empty cells. Check both that the column was mapped and that each cell has a value.

How Dromo handles requiring values

Dromo's required validator flags empty cells, require_with, require_without, and their variants make a field required only when other fields are or are not filled in, and requireMapping stops the user from continuing until a column has been matched to the field.

Frequently asked questions

How do I check for empty values in JavaScript?

Check for null and undefined, then trim strings and compare with an empty string. Avoid if (!value), which also treats 0 and false as empty.

Should N/A count as a missing value?

Usually yes. Values such as N/A, null, none, and a single dash typed into a cell mean nothing was entered, so treat them as missing for required fields, but agree on the exact list for your data.