Optional field crashes the CI

Francis Venne asked on June 16, 2020 17:20

Hi,

I’m working on an MVC website with Kentico.

I have multiples pages with a certain page type but now I need to add an optional CTA field. Usually, I create a non mandatory bool field (ShowCTA), with 2 mandatory fields (Text and URL) whom are only visible if the CTA checkbox is checked.

The solution works well for new page types, but it doesn't for existing page types. The CI crashes because it tries to insert NULL in the mandatory columns.

The solutions I have so far Is to delete all the pages and recreate them, but it’s not really an option, especially since I have multiples environments.

My other solution is to uncheck the “required” checkbox and to add a condition in the view to verify if both fields are not empty, but it’s a bit weird from a user experience POV.

This is my ShowCTA field.

  • Field name : ShowCTA
  • Data type : Boolean
  • Required : no
  • Default value : no
  • Form control : Check box
  • Has depending field : yes

And both my fields look like this

  • Field name : TextCTA
  • Data type : Text
  • Required : yes
  • Default value : ""
  • Form control : Text box
  • Visibility condition: ShowCTA.Value == true
  • Depends on another field : yes

Is there a way to keep the required fields without breaking the CI? Is it perhaps something fixed in later hotfixes (we are at version 12.0.46)?

Thanks in advance!

Recent Answers


David te Kloese answered on June 17, 2020 13:12

Probably new pages don't get the NULL value (but an empty string) stored in that field.

Probably the easiest would be to initially not make it required, and script the update to insert empty string values in the pages you already have; This can be part of the CI using : docs.kentico.com/.../synchronizing-database-changes-not-managed-by-continuous-integration.

And after that make it required using the same way your using it now.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.