getodk / getodk/web-forms

GroupNode.subscribe() should also subscribe on all of its children?

Open
#178 1 comment 0 reactions 0 assignees View on GitHub
xforms-engine
Dominant language
TypeScript
Stars
38
Forks
22
PR merge metrics
No merged PRs in 30d

Description

### Issue:
When a node depends on a group node (by using `string` function) and state of a child of that group changes, the state of the target node is not recomputed. Because `subscribe` of group function doesn't subscribes to the children.

I don't know how much practical this scenario is, based on that we can prioritize.

In the following example value of `/data/result` is computed using `/data/g1` (group) and `/data/g1/t1` (text input), it works when `/data/g1/t1` is updated but not when `/data/g1/t2` is updated. Note that calculate expression of `result` is using implicity `string()` function.

### Example:

```
describe('Subscribe all children of group when group-node is the argument to an XPath function', () => {
it.only('should work', async () => {

const scenario = await Scenario.init(
'get-value-of-all-questions-in-a-group',
html(
head(
title('get-value-of-all-questions-in-a-group'),
model(
mainInstance(
t('data id="get-value-of-all-questions-in-a-group"',
t('g1',
t('t1'),
t('t2')),
t('result'))),
bind('/data/g1/t1').type('string'),
bind('/data/g1/t2').type('string'),
bind('/data/result').type('string').readonly('true()').calculate('concat( /data/g1, /data/g1/t1 )')
)
),
body(group('/data/g1',
input('/data/g1/t1'),
input('/data/g1/t2')
))
)
);

scenario.answer('/data/g1/t1', 'test1 ');
expect(scenario.answerOf('/data/result')).toEqualAnswer(stringAnswer('test1 test1 '));

scenario.answer('/data/g1/t2', 'test2 ');
expect(scenario.answerOf('/data/result')).toEqualAnswer(stringAnswer('test1 test1 ')); // This should be 'test1 test2 test1 '

scenario.answer('/data/g1/t1', 'test1again ');
expect(scenario.answerOf('/data/result')).toEqualAnswer(stringAnswer('test1again test2 test1again '));
});
});
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at GroupNode.subscribe() and reproduce the supplied scenario where /data/result depends on /data/g1 and /data/g1/t1. Verify the subscription behavior when /data/g1/t2 changes; the work is done when the result recomputes to include the updated child value.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.