JSFiddle - React, Tailwind, and code Playground

by brigand

JavaScript

const formState = {
    first_name: 'theskill',
    last_name: 'within',
    currently_insured: null,
    age: null,
    gender: null,
    height_ft: null,
    height_in: null,
    weight: '',
    use_tobacco: null,
    household_size: null,
    estimated_household_income: null,
    address_1: '',
    zip_code: '',
    phone_1: '',
    email: '',
    checkbox: false, // checkboxes are optional
    best_time_to_chat: null,
  }


	const isMissing = (value) => value == null || value == '';

  const validateAllFieldsFilled = () => {
    const fields = Object.keys(formState)
    const missing = fields
      .filter((field) => isMissing(formState[field]));
    console.log(missing)
  }
  
  validateAllFieldsFilled()