XLSForm / pyxform

A Python package to create XForms for ODK Collect.
BSD 2-Clause "Simplified" License
77 stars 134 forks source link

Require labels for items in choice lists #534

Open lognaturel opened 3 years ago

lognaturel commented 3 years ago

Currently, pyxform does not require labels for items in choice lists.

For dynamic selects, I can see an argument for them not being required because users could be building a list they only want to query and won't use in a select. However, I think that's pretty rare and for those advanced users, it's not a big deal to just add a label. In v1.4, if a user did build a dynamic select with a choice missing a label and used it in a select, there'd be a Validate error. In v1.5, there's a crash (narrowly addressed by #535).

For static selects, I don't see any use for a choice without a label. Currently there's no validation on this at all.

CC @MartijnR @pbowen-oc

    def test_choices_without_labels__for_static_selects__allowed(self):
        """
        Test choices without labels for static selects. Validate will NOT fail.
        """
        self.assertPyxformXform(
            md = """
            | survey   |                    |      |       |
            |          | type               | name | label |
            |          | select_one choices | a    | A     |
            | choices  |                    |      |       |
            |          | list_name          | name | label |
            |          | choices            | 1    |       |
            |          | choices            | 2    |       |
            """,
            xml__contains=[
                '<value>1</value>'
            ],
        )

    def test_choices_without_labels__for_dynamic_selects__allowed_by_pyxform(self):
        """
        Test choices without labels for dynamic selects. Validate will fail.
        """
        self.assertPyxformXform(
            md = """
            | survey   |                    |      |       |               |
            |          | type               | name | label | choice_filter |
            |          | select_one choices | a    | A     | true()        |
            | choices  |                    |      |       |
            |          | list_name          | name | label |
            |          | choices            | 1    |       |
            |          | choices            | 2    |       |
            """,
            run_odk_validate=False,
            xml__contains=[
                '<instance id="choices">',
                '<item>',
                '<name>1</name>'
            ],
        )
lognaturel commented 4 months ago

@lindsay-stevens could you please briefly look into how this intersects with https://github.com/XLSForm/pyxform/issues/679? Should we close this?