Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When a select's value is removed because it's no longer available, recalculation is not triggered #661

Open
lognaturel opened this issue Mar 23, 2022 · 0 comments

Comments

@lognaturel
Copy link
Member

lognaturel commented Mar 23, 2022

Software versions

JavaRosa v3.3.0 and prior

Problem description

ItemsetBinding.getChoices() may mutate a select's answer if the previously-selected choice is no longer available:

* SIDE EFFECT: any item currently selected as part of the current question's answer that is no longer

This does not trigger recomputation of dependent values or fire the xforms-value-changed event.

Steps to reproduce the problem

    @Test
    public void removingChoiceFromOptions_triggersRecalculation() throws IOException {
        Scenario scenario = Scenario.init("Select", html(
            head(
                title("Select"),
                model(
                    mainInstance(
                        t("data id='select'",
                            t("filter"),
                            t("select"),
                            t("dependent"))),

                    instance("choices",
                        item("aa", "A"),
                        item("aaa", "AA"),
                        item("bb", "B"),
                        item("bbb", "BB")),
                    bind("/data/dependent").calculate("/data/select"))),
            body(
                input("/data/filter"),
                select1Dynamic("/data/select", "instance('choices')/root/item[starts-with(value,/data/filter)]")
            )));

        scenario.answer("/data/filter", "a");
        scenario.answer("/data/select", "aa");
        assertThat(scenario.answerOf("/data/dependent"), is(stringAnswer("aa")));

        scenario.answer("/data/filter", "q");
        assertThat(scenario.choicesOf("/data/select").isEmpty(), is(true));
        assertThat(scenario.answerOf("/data/select"), nullValue());
        assertThat(scenario.answerOf("/data/dependent"), nullValue());
    }

Expected behavior

Recomputation should be triggered as well as the xforms-value-changed event.

This all is making me wonder about the clearing behavior. It's clearly desired in a conventional cascading select context. There are cases like selects without duplicates (see forum post) where it could be surprising. I believe this has been the behavior forever but that might be worth double checking.

See related tests in SelectOneChoiceFilterTest and DynamicSelectUpdateTest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant