noura_nouri
New Creator

Dynamic Forms | Compare with a value from the Project Settings

Jump to solution

Hello everyone reading this,

I am working with a metadata template in the Rules section to be able to apply the changes dynamically to where the metadata can be used (for example page structure folders etc, if the metadata are active) and there is a portion of the form that can only be visible if a certain CMS_INPUT_TOGGLE is active (or "on").

I tried out with a couple of solutions and they didn't work. I will post the 2 main ones I worked with, that I think could be closer to what can be seen as a potential solution.

The code snippet of the Input Toggle in "Project Settings" Template:

 

 <CMS_GROUP>
    <LANGINFOS>
      <LANGINFO lang="*" label="General"/>
    </LANGINFOS>

    <CMS_INPUT_TOGGLE
      name="ps_use_target_groups"
      type="radio"
      hFill="yes"
      noBreak="yes"
      preset="default"
      singleLine="no"
      useLanguages="yes">
      <LANGINFOS>
        <LANGINFO lang="*" label="Use Targetgroups"/>
        <LANGINFO lang="DE" label="Zielgruppen nutzen"/>
      </LANGINFOS>
    </CMS_INPUT_TOGGLE>

  </CMS_GROUP>

 

 

Code snippet in Form tab in "metadata" template:

 

<CMS_GROUP tabs="top">

    <CMS_LABEL name="md_target_groups_label">
      <LANGINFOS>
        <LANGINFO lang="*" label="The menu entry is visible for the following target groups :"/>
        <LANGINFO lang="DE" label="Die Menüeintrag ist für folgende Zielgruppen sichtbar :"/>
      </LANGINFOS>
    </CMS_LABEL>

    <CMS_INPUT_CHECKBOX name="md_visible_for_target_groups" gridWidth="3" hFill="yes" preset="copy" useLanguages="no">
      <ENTRIES>
        <ENTRY value="End">
          <LANGINFOS>
            <LANGINFO lang="*" label="Endconsumer"/>
          </LANGINFOS>
        </ENTRY>
        <ENTRY value="Inst">
          <LANGINFOS>
            <LANGINFO lang="*" label="Installer"/>
            <LANGINFO lang="DE" label="Installateur"/>
          </LANGINFOS>
        </ENTRY>
      </ENTRIES>
      <LANGINFOS>
        <LANGINFO lang="*" label="Target Groups"/>
        <LANGINFO lang="DE" label="Zielgruppen"/>
      </LANGINFOS>
    </CMS_INPUT_CHECKBOX>

  </CMS_GROUP>

 

 

Example 1 of Rules solution I tried out:

 

    <RULE>
		<IF>
			<EQUAL>
				<PROPERTY name="ps_use_target_groups" source="#global"/>
				<TRUE/>
			</EQUAL>
		</IF>
		<DO>
            <PROPERTY name="VISIBLE" source="#form.md_target_groups_label"/>
			<PROPERTY name="VISIBLE" source="#form.md_visible_for_target_groups"/>

		</DO>
	</RULE>

 

 I do not get any log WARNs nor ERRORs for this one.

Example 2:

 

<RULE>
		<SCHEDULE delay="0" id="targetGroupVisibitySchedule" service="MetaDataValueService">
			<CONDITION>
				<EQUAL>
					<PROPERTY name="VALUE" source="ps_use_target_groups"/>
					<TRUE/>
				</EQUAL>
			</CONDITION>
		</SCHEDULE>
		<DO>
			<PROPERTY name="VISIBLE" source="#form.md_target_groups_label"/>
			<PROPERTY name="VISIBLE" source="#form.md_visible_for_target_groups"/>
		</DO>
	</RULE>

 


I get this log WARN: There is no fact 'VALUE' for item 'ps_use_target_groups'!

I would like to know what I am doing wrong exactly because the form label and corresponding Checkboxes are always visible regardless of whether ps_use_target_groups is on or off.

If I can provide you with any additional informations, please feel free to ask.

Thank you in advance for the help.

Best regards,
Noura

0 Kudos
1 Solution

Accepted Solutions
hoebbel
Crownpeak employee

Hello Noura,

I just checked my answer and found the thinking mistake I made.
We are after all in the metadata - these are language independent. So we can't pass the (not existing) current language to the FormDataValue service to get the data from the project settings page.
I am very sorry for this carelessness error. So step two has to look like this (same as before but without the language param)

	<RULE>
		<SCHEDULE delay="0" id="use_target_groups" service="FormDataValueService">
			<PARAM name="ID">
				<PROPERTY name="PROJECT_PROPERTIES_ID" source="#global"/>
			</PARAM>
			<PARAM name="STORETYPE">
				<TEXT>GLOBALSTORE</TEXT>
			</PARAM>
			<PARAM name="FIELD">
				<TEXT>ps_use_target_groups</TEXT>
			</PARAM>
		</SCHEDULE>
		<DO>
			<PROPERTY name="VALUE" source="md_use_target_groups"/>
		</DO>
	</RULE>

 As long as the toogle component within the projects setting page is language independent, that should work. (if it is language dependent, it still may work 😉 )

Does the toogle component now gets the appropriate value from the project property page? 

Hint: the FormDataValueService only reads stored data. So if you change the value withn the projects property page, you have to save the change!

Best regards
Holger

View solution in original post

4 Replies
hoebbel
Crownpeak employee

Hello Noura,

if I understand it correctly, this is about hiding input components when a certain toggle is [un]set in the project settings.
So a rule should be applied that evaluates values from a completely different form. This is not possible.
Instead, the value from the other form must be transferred to a [hidden] input component and then evaluated by rule. For the transport of the value the FormDataValueService can be used.
First: Define a [hidden] Toggle componente within the metadata template
Second: Define a rule, that uses the FormDataValueService to transport the setting from the project settings to this component.
Link to Documentation
Third: use a rule, that evaluates the [local] component to set the visible status of the other components.

Examples (untested, just as an example how it could look like. Annotation: For testing purposes I recomment not to hide the component, so that you can check, if it is working)
First:

<CMS_INPUT_TOGGLE
  name="md_use_target_groups"
  hidden="yes"
  type="radio"
  hFill="yes"
  noBreak="yes"
  preset="default"
  singleLine="no"
  useLanguages="yes">
  <LANGINFOS>
	<LANGINFO lang="*" label="Use Targetgroups"/>
	<LANGINFO lang="DE" label="Zielgruppen nutzen"/>
  </LANGINFOS>
</CMS_INPUT_TOGGLE>

Second:

<RULE>
  <SCHEDULE delay="0" id="use_target_groups" service="FormDataValueService">
    <PARAM name="ID">
      <PROPERTY name="PROJECT_PROPERTIES_ID" source="#global"/>
    </PARAM>
    <PARAM name="STORETYPE">
      <TEXT>GLOBALSTORE</TEXT>
    </PARAM>
    <PARAM name="FIELD">
      <TEXT>ps_use_target_groups</TEXT>
    </PARAM>
    <PARAM name="LANGUAGE">
      <PROPERTY source="#global" name="LANG"/>
    </PARAM>
  </SCHEDULE>
  <DO>
    <PROPERTY name="VALUE" source="md_use_target_groups"/>
  </DO>
</RULE>

Third: your example 1, just adapt the component name to the hidden local component.

best regards
Holger

 

0 Kudos
noura_nouri
New Creator

Hello Holger,

Thank you so much for your time and response.

I tested our the solution you provided, it doesn't seem to be working. I am assuming that the md_use_target_groups "variable" is not being set correctly, because when I turn its hidden option to "no", it shows no value (neither On nor Off), even when I set it manually nothing changes.

And I get the following warning in the logs: (de.espirit.firstspirit.forms.rules.NotFact): Cannot compute inverse value of 'null'

Here's the new code I used:

 

 

<RULE>
		<SCHEDULE delay="0" id="use_target_groups" service="FormDataValueService">
			<PARAM name="ID">
				<PROPERTY name="PROJECT_PROPERTIES_ID" source="#global"/>
			</PARAM>
			<PARAM name="STORETYPE">
				<TEXT>GLOBALSTORE</TEXT>
			</PARAM>
			<PARAM name="FIELD">
				<TEXT>ps_use_target_groups</TEXT>
			</PARAM>
			<PARAM name="LANGUAGE">
				<PROPERTY name="LANG" source="#global"/>
			</PARAM>
		</SCHEDULE>
		<DO>
			<PROPERTY name="VALUE" source="md_use_target_groups"/>
		</DO>
	</RULE>
	<RULE>
		<IF>
			<EQUAL>
				<PROPERTY name="VALUE" source="md_use_target_groups"/>
				<FALSE/>
			</EQUAL>
		</IF>
		<DO>
			<NOT>
				<PROPERTY name="VISIBLE" source="#form.meta_target_groups"/>
			</NOT>
		</DO>
	</RULE>

 

 


meta_target_groups being the name of the CMS_GROUP

I also tried all different variations of the code, namely:
1. testing if the toggle is equal to True and removing the NOT tags
2. using the components within that cms_group and setting them to visible/not visible
3. listing all other cms_groups and setting their visibility
4. using <WITH> <FALSE/> </WITH> <DO>...</DO> after the IF statement block
5. with and without #form.
etc

Nothing seems to be working, the value of the input toggle doesn't seem to be passed correctly or maybe not read correctly, maybe.

Do you have any ideas what might be the cause of the problem here?

Thank you again!
Best regards,
Noura

0 Kudos
hoebbel
Crownpeak employee

Hello Noura,

I just checked my answer and found the thinking mistake I made.
We are after all in the metadata - these are language independent. So we can't pass the (not existing) current language to the FormDataValue service to get the data from the project settings page.
I am very sorry for this carelessness error. So step two has to look like this (same as before but without the language param)

	<RULE>
		<SCHEDULE delay="0" id="use_target_groups" service="FormDataValueService">
			<PARAM name="ID">
				<PROPERTY name="PROJECT_PROPERTIES_ID" source="#global"/>
			</PARAM>
			<PARAM name="STORETYPE">
				<TEXT>GLOBALSTORE</TEXT>
			</PARAM>
			<PARAM name="FIELD">
				<TEXT>ps_use_target_groups</TEXT>
			</PARAM>
		</SCHEDULE>
		<DO>
			<PROPERTY name="VALUE" source="md_use_target_groups"/>
		</DO>
	</RULE>

 As long as the toogle component within the projects setting page is language independent, that should work. (if it is language dependent, it still may work 😉 )

Does the toogle component now gets the appropriate value from the project property page? 

Hint: the FormDataValueService only reads stored data. So if you change the value withn the projects property page, you have to save the change!

Best regards
Holger

noura_nouri
New Creator

Hi Holger,

Thank you so much for your help.
Removing the language parameter was really helpful.
The problem is now solved.

Best regards,
Noura

0 Kudos