opencrvs / opencrvs-core

A global solution to civil registration
https://www.opencrvs.org
Other
85 stars 67 forks source link

Enable custom form sections for form configuration #6810

Open rikukissa opened 5 months ago

rikukissa commented 5 months ago

Description

We've been asked for custom form sections in multiple projects now. In Burkina Faso, we were able to achieve custom sections doing a small core modification:

Country config

{
  id: 'mention',
  viewType: 'form',
  name: {
    defaultMessage: 'Mention',
    description: 'Form section name for Mention',
    id: 'form.section.mention.name'
  },
  title: {
    defaultMessage: 'Détails de la mention',
    description: 'Form section title for Mention',
    id: 'form.section.mention.title'
  },
  groups: [/* ... */], // All fields are custom fields inside this
},

To test while developing as these two as what break the first:

There's a chance this is in reality to do with the section not shown as part of declaration but then shown as part of correction. When you come back to correct and change the fields value it doesn't activate the "Continue" button as it thinks you didn't change anything

Tasks

if (!originalData) return false

and consider if it should be possible that one section, for instance custom "mentions" section is completely empty when the form is first submitted so originalData = undefined but is filled up in correction. Explore if it's possible to add more sections in the correction process.

Implementation like

hasFieldChanged(
  field: IFormField,
  data: IFormSectionData,
  originalData?: IFormSectionData
) {
  if (!originalData) {
    const hasChanged = true
    this.hasChangesBeenMade = this.hasChangesBeenMade || hasChanged
    return hasChanged
  }

could also solve things without needing to add custom section transformers

rikukissa commented 3 months ago

This ticket can be closed when https://github.com/opencrvs/opencrvs-core/pull/7023 is merged @tahmidrahman-dsi @Zangetsu101.

@SyedaAfrida @jpye-finch we need to add a completely custom section to one of the Farajaland forms to ensure this works. Could you define one please?

jpye-finch commented 3 months ago

@rikukissa Could the Witness pages in the Marriage form be considered as one?

rikukissa commented 3 months ago

@jpye-finch definitely. Now that I think about, we don't really have to even have a conceptual distinction between "custom sections" and "standard sections". They all could just be sections