formcreator icon indicating copy to clipboard operation
formcreator copied to clipboard

Relation between fields

Open OsamaDengler opened this issue 3 years ago • 5 comments

Is your feature request related to a problem? Please describe. I've had varous situations where data in one field depends on the content of another field.

Example: form creating a request to modify user data in ActiveDirectory

Field 1: desired user Field 2: List of possible LDAP attributes Field 3: Current LDAP attribute value

As of today I have't found a way to realize this because Field 3 depends on the content of field 1 and field 2 to create the LDAP search filter. Other usecases: populate a select field depending on the content of another field, pre-select a radio-button depending on the value of another field,...

Describe the solution you'd like I'd like to define the LDAP search filter of field 3 to depend on the content of field 1 and field 2. More generically speaking: I'd like to specify relations between fields.

Describe alternatives you've considered Haven't found any so far.

Additional context I'd volunteer to help with coding but I'd need a kickoff because the code is rather big and documentation is not so comprehensive :-)

OsamaDengler avatar Apr 04 '22 18:04 OsamaDengler

Hi

Relations between fields is not supported. You need new types of questions designed specifically for your need.

Currently there is no plan to build a relationship able to modelize generic use cases (not studied yet).

btry avatar Apr 04 '22 18:04 btry

Hi thanks for Your reply.

I'm aware that this is not supported, that's why I flagged it as feature proposal :-)

Is there documentation available on how to implement new types of questions?

Thanks

OsamaDengler avatar Apr 04 '22 19:04 OsamaDengler

Long ago, in a version far far away, Formcreator had a specific question type implementing dependencies with 2 other questions.

The dependencies were modelized with PluginFormcreatorQuestionDependency (still exists). This class is similar to pluginFormcreatorQuestionRegex and PluginFormcreatorQuestionRange. It stores a dependency to an other question in the form.

You need to harvest in the 2 files below to create your new question type with at least 1 parameter of type PluginFormcreatorQuestionDependency. You need to read code of questions using parameters to find how to build the question design modal window. I recommend you to code for the develop branch. It uses Twig and it is simpler than 2.12 to implement (less mess with Ajax calls).

Next, you need to add some logic to maintain the functional relation between question when a form is displayed for a requester. No example available on GitHub unfortunately. Then feel free to do it as you want. You will probably need some JS. If you need Ajax, then when formcreator sends the state of the answers to the server, the server may needs ability to feed back to the browser some data to "drive" the behaviour of your new question type. This needs a simple but wise design to make it evolutive.

There is no documentation to describe the internal design of the plugin, and questions parameters design is complicated for now. You need to read what already exists and read the code.

https://github.com/pluginsGLPI/formcreator/blob/develop/tests/fixture/PluginFormcreatorDependentField.php

https://github.com/pluginsGLPI/formcreator/blob/develop/inc/questiondependency.class.php

btry avatar Apr 04 '22 20:04 btry

Thanks a lot for the explanation. Will 2.12 be compatible with GLPI 9.5 or is it GLPI 10 only?

I will give it a try and hope the force will be with me...

OsamaDengler avatar Apr 04 '22 20:04 OsamaDengler

Hi

Version 2.12 is for glpi 9.5, Version 2.13 is for glpi 10.

btry avatar Apr 05 '22 05:04 btry