Skip to content

Spike adding field validation UI feedback

Andrew Price edited this page May 3, 2019 · 9 revisions

Introduction

There is a requirement to prevent surveys launching when there are still validation errors.

https://trello.com/c/7DKHeOHG/1067-spike-validator-question-title-1-day

Scope

This spike will investigate a possible approach and provide a PoC. This builds on a previous investigative spike: https://github.com/ONSdigital/eq-author-app/wiki/Validation-for-Authors-Spike and is based on prototype https://author.netlify.com/#/eq-author/

The PoC is on this branch: https://github.com/ONSdigital/eq-author-app/compare/1067-spike-validator-question-title-1-day

Specifically, we need to address:

  1. How error validations should be represented in the schema
  2. How a page/answer decides if something is invalid
  3. How a question page calculates & displays the total number of errors
  4. How a new question page is identified - a newly created page doesn't immediately show validation errors
  5. How a new answer is identified - a newly created answer doesn't immediately show validation errors
  6. How the Launch Survey button is only enabled when there are no validation errors

1. How error validations should be represented in the schema

A previous spike https://github.com/ONSdigital/eq-author-app/wiki/Validation-for-Authors-Spike and is based on prototype https://author.netlify.com/#/eq-author/ looked at different approaches to storing the validation. Two options considered are:

  1. Raise an Error when invalid data submitted - this prevents invalid data from being stored. Not technically what we want as we need the user to be able to save invalid data, just not to be able to launch a survey
  2. Create a validationError property on the question/answer objects - this allows invalid data to be saved and relies on UI to report on validation errors

A new GraphQL fragment has been created to represent validation errors:

fragment ValidationErrorInfo on QuestionPage {
  validationErrorInfo {
    errors {
      field
      message
    },
    totalCount
  }
}

where totalCount = number of errors on page + child answers

Clone this wiki locally