Is it possible to have a Conditional Style apply to multiple fields?

  • 9 October 2018
  • 4 replies
  • 27 views

Hello,

 

I have a scenario in which I am using Conditional Styles to show a red border around certain mandatory fields. This is dependant on a hidden checkbox being ticked, as sometimes the fields will be optional.

 

At the moment I am having to create the Conditional Field from scratch for each of the individual fields.

Is there a way to have a generic Conditional Style which I can apply to all of the fields in K2 Five (5.1)? 

 

Kind of like how Unbound Rules work, but for Styles.

 

Kind Regards,

Josh


4 replies

Userlevel 5
Badge +12

You can set control properties via rules, so that when that checkbox changes you set the properties of all the related controls to toggle their red border. Not that much easier than putting the custom style on each control but a little more manageable.

Hello tbyrne777,


Thanks for the reply.

 

I tried doing this via rules at first, but the Styles and Conditional Styles properties are greyed out when you try to change the properties of a field via rules.

 

Kind Regards,

Josh

Badge +2

Does anyone know the conditions under which Styles and Conditional Styles properties are greyed out when you try to change the properties of a field via rules?

Badge +2

Conditional formatting appears to only apply when the form is first loaded, not when the form is submitted - that would probably be the more common time when you would want to conditionally format some data, i.e. when validation has occurred. Given the example at https://help.k2.com/onlinehelp/k2five/userguide/5.0/default.htm#Create/K2Designer/Styles/ConditionalStyles.htm it appears that the conditional formatting logic is triggered with a javascript onchange event so, to get around this limitation, I set the control's text property to trigger the conditional check, e.g. checking for empty with the formatting and then moving an empty string to the field after initially moving some random value to it, having checked that the field was empty in the first place so as not to erase any entered data.  The rule coding was achieved in combination with a data label that indicated whether the page had loaded, so that the formatting was not applied when the page first loads.


Reply