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
| sku | price | inStock |
|---|---|---|
| A-100 | 0 | false |
| (spaces only) | 19.99 | true |
| A-102 | N/A | true |
| A-103 | 5 | (missing) |
Output
| Row | Missing (correct check) | Missing (!value check) |
|---|---|---|
| 1 | none | price, inStock |
| 2 | sku | none |
| 3 | price | none |
| 4 | inStock | inStock |
Edge cases to handle
- Zero and false. A price of
0or aninStockoffalseis a real answer. Never use a truthy check for required fields. - Placeholders.
N/A,null,-, andnonetyped into a cell usually mean nothing was entered. ButNAis also Namibia's country code andNonecan 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.
Related terms
- Flagging Invalid Rows: Marking rows that fail validation so they can be fixed, not deleted.
- Dropping Invalid Rows: Removing rows that fail validation, while keeping a record of why.
- Imputing Missing Values: Filling in missing values with a substitute, or deciding not to.
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.