Skip to content

Fix: Decidim::Admin::ComponentForm validations#5269

Merged
oriolgual merged 12 commits intodecidim:masterfrom
CodiTramuntana:fix/component_form_validations
Jul 25, 2019
Merged

Fix: Decidim::Admin::ComponentForm validations#5269
oriolgual merged 12 commits intodecidim:masterfrom
CodiTramuntana:fix/component_form_validations

Conversation

@aitorlb
Copy link
Copy Markdown
Contributor

@aitorlb aitorlb commented Jul 14, 2019

🎩 What? Why?

It's possible to create a Component even if the "required" fills are empty

Decidim::Admin::ComponentForm was only validating:

  • the translatable attribute :name
  • custom validation methods

but was not validating the "settings" attributes:

  • :settings
  • :default_step_settings
  • :step_settings

Because in Decidim::Admin::ComponentsController, in the actions were the @form.valid? is called, the @form was being builded #from_params, and so the "settings" attributes were assigned a Hash, which caused Rectify::Form#form_attributes_valid? to ignore them as they did not respond_to?(&:valid?). Also it caused the views to break if the @form was invalid (i.e. empty name), because the logic in the views depended on the form attributes to be of the correct type, which was only possible when it was builded #from_model (like in the controller actions #new and #edit).

This was fixed by processing the params before building the @form in the controller. Besides, I had to overwrite Rectify::Form#form_attributes_valid? in Decidim::Admin::ComponentForm anyways because the nested attributes inside :step_settings were not being reached.

Also, I encountered the problem that the TranslatablePresenceValidator used to validate translatable attributes expects the record to respond either to #default_locale or #current_organization, which wasn't the case. So I updated Decidim::SettingsManifest#schema to allow passing a :default_locale argument.

Important

Because all of the component's settings default to required: true, and only a handful of them overwrite this default value, the component form validations was causing situations like the one in the gif, where a checkbox that supposedly gives a configuration option is required to be checked in order to pass the form validations, which means that is no longer an option to the user...

To fix the above, I opted for updating the default value to false in Decidim::SettingsManifest::Atribute. So I imagine that if this PR gets merged there will be component settings that will need to be updated to required: true to retain the expected behaviour. cc @decidim/product

📌 Related Issues

📋 Subtasks

  • Add CHANGELOG entry
  • Add tests

📷 Screenshots (optional)

component_form_meeting-optimized

@aitorlb aitorlb marked this pull request as ready for review July 15, 2019 21:31
@aitorlb aitorlb requested a review from a team as a code owner July 15, 2019 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Terms and conditions aren't shown on an event registration process

2 participants