Fix: Decidim::Admin::ComponentForm validations#5269
Merged
oriolgual merged 12 commits intodecidim:masterfrom Jul 25, 2019
Merged
Fix: Decidim::Admin::ComponentForm validations#5269oriolgual merged 12 commits intodecidim:masterfrom
oriolgual merged 12 commits intodecidim:masterfrom
Conversation
oriolgual
approved these changes
Jul 25, 2019
2 tasks
2 tasks
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎩 What? Why?
Decidim::Admin::ComponentFormwas only validating::namebut was not validating the "settings" attributes:
:settings:default_step_settings:step_settingsBecause in
Decidim::Admin::ComponentsController, in the actions were the@form.valid?is called, the@formwas being builded#from_params, and so the "settings" attributes were assigned aHash, which causedRectify::Form#form_attributes_valid?to ignore them as they did notrespond_to?(&:valid?). Also it caused the views to break if the@formwas 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#newand#edit).This was fixed by processing the params before building the
@formin the controller. Besides, I had to overwriteRectify::Form#form_attributes_valid?inDecidim::Admin::ComponentFormanyways because the nested attributes inside:step_settingswere not being reached.Also, I encountered the problem that the
TranslatablePresenceValidatorused to validate translatable attributes expects therecordto respond either to#default_localeor#current_organization, which wasn't the case. So I updatedDecidim::SettingsManifest#schemato allow passing a:default_localeargument.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 torequired: trueto retain the expected behaviour. cc @decidim/product📌 Related Issues
📋 Subtasks
CHANGELOGentry📷 Screenshots (optional)