enketo-core icon indicating copy to clipboard operation
enketo-core copied to clipboard

Readonly status can be lifted when ancestor group becomes relevant

Open MartijnR opened this issue 5 years ago • 1 comments

http://localhost:8005/?xform=Read.Only.xml

Looks like I took a wrong turn at some point. The disable function in a modern widget is used to make a widget readonly, which done when:

  1. during widget initialization when a question has a <bind> with readonly="true()"
  2. a question or its ancestor becomes irrelevant

The reason for 2, is to cater to views that show irrelevant questions, and to provide some extra security for users that hack around in the dev console. That seems correct to me.

The enable function is supposed to be the opposite of disable and is called when:

  1. the question becomes relevant (directly or via ancestor)

This is where the flaw is.

Some widgets do not have the flaw as they include the wrapper if (!this.props.readonly){} in the enable function. We could do that in all widgets. However, soon readonly will not be a static condition anymore https://github.com/enketo/enketo-core/issues/391, so it may be worth thinking about that already when resolving this issue.

MartijnR avatar Apr 01 '19 20:04 MartijnR

I think this is the way forward: https://github.com/enketo/enketo-core/issues/391#issuecomment-478742942,

so for now:

  • [ ] remove all if(!this.props.readonly) wrappers from widgets
  • [ ] add readonly check to widgets controller whenever enable is called

MartijnR avatar Apr 01 '19 20:04 MartijnR