lizmap-web-client icon indicating copy to clipboard operation
lizmap-web-client copied to clipboard

[Question]: form layout/drag and drop designer - container/control visibility by expression

Open josemvm opened this issue 2 years ago • 9 comments

What is the question?

i'm trying to control container visibility by expression like @lizmap_user = 'jose' or @lizmap_user_groups = 'dafaj' but the contaneir is always visible for all users or groups

imagem

thanks for your help

Versions

Versions :

  • Lizmap Web Client : 3.6.4
  • Lizmap plugin : 3.14.0
  • QGIS Desktop : 3.22.16
  • QGIS Server : 3.22.16
  • Py-QGIS-Server : not used
  • QGIS Server plugin atlasprint : 3.3.2
  • QGIS Server plugin lizmap_server : 2.7.1
  • QGIS Server plugin wfsOutputExtension : 1.7.1

Check Lizmap plugin

  • [X] I have done the step just before in the Lizmap QGIS desktop plugin before opening this ticket. Otherwise, my ticket is not considered valid and might get closed.

QGIS server version, only if the section above doesn't mention the QGIS Server version

No response

Operating system

Ubuntu 20.04

Browsers

Firefox

Browsers version

lasted

Relevant log output

No response

josemvm avatar Jun 05 '23 11:06 josemvm

https://github.com/3liz/lizmap-web-client/issues/2535 ?

josemvm avatar Jun 05 '23 11:06 josemvm

@lizmap_user_groups = 'dafaj'

This will never work for sure, because it's an array, not a string. You can look the variable help for it.

Then for string, this must be checked. You can still check QGIS server logs when opening the form, you will see if the expression is evaluated correctly and if yes, with which parameters were used

Gustry avatar Jun 05 '23 13:06 Gustry

i'm trying to use login field ("login" = 'jose') to control de visibility using this script as usual for me https://docs.lizmap.com/current/en/publish/customization/javascript.html#send-current-login-user-id but with this way the container remains always invisible for all users


i'm trying too with a cod_divisao_serv field which has a relation reference widget type (the best pratice for my propose) imagem like "cod_divisao_serv" = 9 imagem the container is always invisible!

josemvm avatar Jun 05 '23 13:06 josemvm

the form needs a interaction, a choice make by the user on one field, it doesn´t assume loaded values like @lizmap_user , "login" = 'jose' or "cod_divisao_serv" = 9

am i right?

josemvm avatar Jun 05 '23 14:06 josemvm

from qgis server logs, i can detect that there are 3 moments:

  • when the user open the form
14:51:25 INFO Server[54807]: **_EXPRESSIONS_**:{"jforms_view_edition-group9":" \"tipo\"  =  'RQI' "}
14:51:25 INFO Server[54807]: **_FEATURE_**:{"type":"Feature","geometry":null,"properties":{"tipo":""}}
14:51:25 INFO Server[54807]: FORM_SCOPE:true
14:51:25 INFO Server[54807]: LAYER:p_cabimentos
14:51:25 INFO Server[54807]: MAP:/var/www/html/lizmap_web_client/lizmap/install/ma/gestaoCabimentos.qgs
14:51:25 INFO Server[54807]: REQUEST:Evaluate
14:51:25 INFO Server[54807]: SERVICE:EXPRESSION
14:51:25 INFO Lizmap[54807]: Request headers provided
14:51:25 INFO Lizmap[54807]: No lizmap user groups in request headers
14:51:25 INFO Lizmap[54807]: Request headers provided
14:51:25 INFO Lizmap[54807]: No lizmap user login in request headers
14:51:25 INFO Lizmap[54807]: **_Sending JSON response_** : {'status': 'success', 'results': [{'jforms_view_edition-group9': 0}], 'errors': [{'jforms_view_edition-group9': ' "tipo"  =  \'RQI\' '}], 'features': 0}
  • when the user write or choice a value on the field include into the expression
14:52:13 INFO Server[54807]: **_EXPRESSIONS_**:{"jforms_view_edition-group9":" \"tipo\"  =  'RQI' "}
14:52:13 INFO Server[54807]: **_FEATURE_**:{"type":"Feature","geometry":null,"properties":{"tipo":"Empreitada"}}
14:52:13 INFO Server[54807]: FORM_SCOPE:true
14:52:13 INFO Server[54807]: LAYER:p_cabimentos
14:52:13 INFO Server[54807]: MAP:/var/www/html/lizmap_web_client/lizmap/install/ma/gestaoCabimentos.qgs
14:52:13 INFO Server[54807]: REQUEST:Evaluate
14:52:13 INFO Server[54807]: SERVICE:EXPRESSION
14:52:13 INFO Lizmap[54807]: Request headers provided
14:52:13 INFO Lizmap[54807]: No lizmap user groups in request headers
14:52:13 INFO Lizmap[54807]: Request headers provided
14:52:13 INFO Lizmap[54807]: No lizmap user login in request headers
14:52:13 INFO Lizmap[54807]: **_Sending JSON response_** : {'status': 'success', 'results': [{'jforms_view_edition-group9': 0}], 'errors': [{'jforms_view_edition-group9': ' "tipo"  =  \'RQI\' '}], 'features': 0}
  • when the qgis validate de value into the expression (0 or 1)
14:53:11 INFO Server[54807]: **_EXPRESSIONS_**:{"jforms_view_edition-group9":" \"tipo\"  =  'RQI' "}
14:53:11 INFO Server[54807]: **_FEATURE_**:{"type":"Feature","geometry":null,"properties":{"tipo":"RQI"}}
14:53:11 INFO Server[54807]: FORM_SCOPE:true
14:53:11 INFO Server[54807]: LAYER:p_cabimentos
14:53:11 INFO Server[54807]: MAP:/var/www/html/lizmap_web_client/lizmap/install/ma/gestaoCabimentos.qgs
14:53:11 INFO Server[54807]: REQUEST:Evaluate
14:53:11 INFO Server[54807]: SERVICE:EXPRESSION
14:53:11 INFO Lizmap[54807]: Request headers provided
14:53:11 INFO Lizmap[54807]: No lizmap user groups in request headers
14:53:11 INFO Lizmap[54807]: Request headers provided
14:53:11 INFO Lizmap[54807]: No lizmap user login in request headers
14:53:11 INFO Lizmap[54807]: **_Sending JSON response_** : {'status': 'success', 'results': [{'jforms_view_edition-group9': **_1_**}], 'errors': [{'jforms_view_edition-group9': ' "tipo"  =  \'RQI\' '}], 'features': 0}


without inteaction on the field included into the expression only the first moment happens

14:56:08 INFO Server[55003]: **_EXPRESSIONS_**:{"jforms_view_edition-group9":" \"cod_divisao_serv\"  = 9"}
14:56:08 INFO Server[55003]: **_FEATURE_**:{"type":"Feature","geometry":null,"properties":{"cod_divisao_serv":""}}
14:56:08 INFO Server[55003]: FORM_SCOPE:true
14:56:08 INFO Server[55003]: LAYER:p_cabimentos
14:56:08 INFO Server[55003]: MAP:/var/www/html/lizmap_web_client/lizmap/install/ma/gestaoCabimentos.qgs
14:56:08 INFO Server[55003]: REQUEST:Evaluate
14:56:08 INFO Server[55003]: SERVICE:EXPRESSION
14:56:08 INFO Lizmap[55003]: Request headers provided
14:56:08 INFO Lizmap[55003]: No lizmap user groups in request headers
14:56:08 INFO Lizmap[55003]: Request headers provided
14:56:08 INFO Lizmap[55003]: No lizmap user login in request headers
14:56:08 INFO Lizmap[55003]: **_Sending JSON response_** : {'status': 'success', 'results': [{'jforms_view_edition-group9': 0}], 'errors': [{'jforms_view_edition-group9': ' "cod_divisao_serv"  = 9'}], 'features': 0}

by this way the qgis server can't validate pre-populated fields or fields without interaction by the user imagem


can i do something (any trick) to make it work from lizmap form?

many thanks

josemvm avatar Jun 05 '23 16:06 josemvm

Hiya! This issue has gone quiet. 👻 We get a few questions in the bug tracker, we are currently slowly closing issues. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Thanks for being a part of the Lizmap community! 🦎

github-actions[bot] avatar Feb 14 '24 04:02 github-actions[bot]

this issue is still valid. the expression @lizmap_user = 'jose' does not work for the container visibility control

josemvm avatar Apr 25 '25 19:04 josemvm

Hi everyone!

Out of the three Lizmap variables available in QGIS – @lizmap_user, @lizmap_user_groups, and @lizmap_repository – only the last one, @lizmap_repository, is not receiving any value in my case.

However, while @lizmap_user and @lizmap_user_groups do receive values, they cannot be used directly in form widget visibility expressions.

This affects the visibility control for containers or groups of fields in QGIS forms.

Although these variables work fine in default values, they do not evaluate properly in visibility logic.


For example, the following expressions do not work:

@lizmap_user IS NOT NULL AND @lizmap_user != ''
array_contains(@lizmap_user_groups, 'admins')

These are either ignored or always return false when used in a visibility condition.


✅ Workaround: Use a hidden "bypass" field

A solid workaround is to create a hidden field in the form that captures the value of the variable using a default value.

You then reference this field in your visibility logic.


🔹 Example 1: Using @lizmap_user

  1. Add a text field named "login" (or any name).
  2. Set its default value to:
@lizmap_user
  1. Use this expression for visibility:
"login" IS NOT NULL AND "login" != ''

🔹 Example 2: Using @lizmap_user_groups

  1. Reuse the same "login" field or create another one.
  2. Set its default value to:
array_to_string(@lizmap_user_groups, ',')
  1. Use this expression to check for the group admins:
"login" LIKE '%admins%'

✅ Final Result

With this setup, form containers can be shown or hidden properly based on:

  • the authenticated user (@lizmap_user), or
  • their group membership (@lizmap_user_groups)

This method ensures visibility logic works even if direct use of Lizmap variables is not supported in visibility expressions.

Thanks a lot for the amazing work on Lizmap and its QGIS integration! 🙌

josemvm avatar Apr 26 '25 16:04 josemvm

Thanks @josemvm for this detailed answer. It bas been closed by the bot, because you created a "question". A question couldn't be open for ever. It's either a "bug" or a "request". Changing it

Gustry avatar Apr 28 '25 09:04 Gustry