Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removing existing image and adding a new one #4599

Merged
merged 3 commits into from
Jul 30, 2021

Conversation

javierm
Copy link
Member

@javierm javierm commented Jul 27, 2021

References

Objectives

  • Make sure editing existing images works properly
  • Fix display rules for attachment validation error messages

This way we save a couple of database insertions and browser requests.
We introduced a bug in commit acbd1b0.

When editing a record and removing an existing image, we don't remove
the HTML fields associated with that image but simply hide them, and
then we add fields to create a new image when clicking on "Add image".

This is standard cocoon behavior. However, since in the case of images
there's a `has_one` relation, cocoon doesn't add unique identifiers to
the new fields, generating duplicate IDs, which is invalid HTML.

Since there's a duplicate file input ID, clicking on the "Choose image"
label we aren't clicking on the new input but on the old one. This means
we aren't correctly attaching an image. The tests passed because
Capybara uses the equivalent of a keyboard to select the field, and in
this case everything worked properly.

So we need to delete the existing elements before inserting new ones.
We're adding a test to check there aren't duplicate IDs.
@javierm javierm added the Bug label Jul 27, 2021
@javierm javierm added this to Reviewing in Consul Democracy via automation Jul 27, 2021
@javierm javierm self-assigned this Jul 27, 2021
In commit cc6f939 we made the images and documents file inputs
invisible (instead of using `display: none`) in order to make it
possible to attach images and documents using the keyboard.

However, since the error messages associated to these inputs has the
same HTML class as the inputs, we were also hiding them (the `display:
none` didn't affect the error messages because they've also got the
`is-visible` class).

Using the `[type=file]` selector we make it more explicit that we only
want to style these inputs.

I'm not adding a test for this scenario because technically the text is
there and I'm not sure how to test for the presence of invisible
elements.
@taitus taitus self-assigned this Jul 30, 2021
Consul Democracy automation moved this from Reviewing to Testing Jul 30, 2021
@javierm javierm merged commit a8c4cc3 into master Jul 30, 2021
@javierm javierm deleted the invalid_image_fields_html branch July 30, 2021 14:03
Consul Democracy automation moved this from Testing to Release 1.4.0 Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants