KOBOCOLLECT: validation constraints - Select Question


In KoboCollect, you can achieve this by using validation constraints and a combination of question logic. Here's how to set it up:

  1. Create a Multiple-Select Question
    Define your multiple-select question with the options:

    • Pragas
    • Doenças
    • Escassez_chuvas
    • Acesso_chuvas
    • Outro
    • Nenhum
  2. Add a Constraint for the "Nenhum" Option
    Use a validation constraint to ensure that if "Nenhum" is selected, no other options can be selected, and vice versa.

    Constraint Expression:

    not(selected(., 'Nenhum') and (count-selected(.) > 1))

    Constraint Message:
    Add a custom error message like:
    "If 'Nenhum' is selected, no other option can be selected."

  3. Add a Notification for Conflicting Choices
    You can use a note question that appears conditionally if both "Nenhum" and any other option are selected. Add this note as a warning.

    Relevant Expression for Note:

    selected(., 'Nenhum') and (count-selected(.) > 1)

    Note Content:
    "You cannot select 'Nenhum' along with other options. Please revise your selection."

  4. Conditional Logic for "Outro" Field
    If "Outro" is selected, you may want to display a text field for the user to specify the "Other" reason. Use the relevant field to conditionally show the text field.

    Relevant Expression for the text field:

    selected(., 'Outro')

Final Steps

  • Test the form thoroughly to ensure the logic works as expected.
  • Upload the XLSForm to KoboToolbox or edit directly in the form builder.
============================================================================

Dans KoboCollect, vous pouvez configurer cette logique en utilisant des contraintes de validation et une combinaison de logique conditionnelle. Voici les étapes en français :


1. Créer une question à choix multiple

Ajoutez une question à choix multiple avec les options suivantes :

  • Pragas
  • Doenças
  • Escassez_chuvas
  • Acesso_chuvas
  • Outro
  • Nenhum

2. Ajouter une contrainte pour l'option "Nenhum"

Utilisez une contrainte de validation pour garantir que si "Nenhum" est sélectionné, aucune autre option ne peut être choisie, et inversement.

Expression de la contrainte :

not(selected(., 'Nenhum') and (count-selected(.) > 1))

Message de contrainte :
Ajoutez un message d'erreur personnalisé, par exemple :

"Si 'Nenhum' est sélectionné, aucune autre option ne peut être choisie."


3. Ajouter une notification pour les choix contradictoires

Ajoutez une question de type note qui s'affichera uniquement si "Nenhum" et une autre option sont sélectionnés en même temps.

Expression de pertinence pour la note :

selected(., 'Nenhum') and (count-selected(.) > 1)

Contenu de la note :

"Vous ne pouvez pas sélectionner 'Nenhum' avec d'autres options. Veuillez modifier votre choix."


4. Afficher un champ texte si "Outro" est sélectionné

Si l'utilisateur sélectionne "Outro", vous pouvez afficher un champ texte pour qu'il précise la raison. Utilisez le champ pertinence pour afficher ce champ conditionnellement.

Expression de pertinence pour le champ texte :

selected(., 'Outro')

Étapes finales

  • Testez le formulaire pour vérifier que la logique fonctionne comme prévu.
  • Téléchargez le fichier XLSForm sur KoboToolbox ou modifiez directement le formulaire dans l'interface.

Did you find this article useful?



  • Exporting and Downloading Your Data

    Exporting and Downloading Your Data Last updated: 22 Sep 2022 KoboToolbox allows you to download the data you have collected in several different...

  • Project Summary

    Project Summary Last updated: 28 May 2020 The Project Summary tab gives you a visual display of all the high-level information related to your pr...

  • Record Validation

    Record Validation Last updated: 19 Jun 2020 A Project owner can now give a “Can Validate” permission to other users. Users with this ...

  • Viewing and Creating Custom Reports

    Viewing and Creating Custom Reports Last updated: 15 Feb 2022 Learn how to navigate and manage the data in the Reports page. On the Reports page...

  • Mapping, Sharing, and Exporting GPS Data

    Mapping, Sharing, and Exporting GPS Data Last updated: 15 Feb 2022 Your project may include a one or more GPS questions in its form. KoboToolbox ...