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

Some form data persisting [""] instead of [] for blank entries #807

Closed
1 task done
sjproctor opened this issue Sep 12, 2024 · 5 comments
Closed
1 task done

Some form data persisting [""] instead of [] for blank entries #807

sjproctor opened this issue Sep 12, 2024 · 5 comments
Labels
M2 Milestone 2 Valkyrie

Comments

@sjproctor
Copy link
Contributor

sjproctor commented Sep 12, 2024

Summary

Data fields that appear blank are rendering on the works show page. This is because at some point during form submission some attributes get assigned [""] if there is no data.

The commit 17489e60223a00d62b36525adc66c09ce1fa630a on Adventist Knapsack provided a temporary solution for the client.

The fields are:

  • Date issued
  • Publication date
  • Publication status
  • Issue
  • Date submitted
  • Date accepted
  • Date available

Acceptance Criteria

  • If fields are blank they do not display

Testing Instructions

  • Revert the code in app/renderers/hyrax/renderers/attribute_renderer.rb from return markup if Array.wrap(values).first.blank? && !options[:include_empty] to return markup if values.blank? && !options[:include_empty]
  • Create a work with only the required metadata. Visit its show page.
  • Blank metadata properties should not be displayed.

Notes

This appears to happen most often on data values.
Ref: #771

@sjproctor
Copy link
Contributor Author

Possibly related: When editing a work, fields that can contain multiple inputs often have a blank second value added.
Image

@ShanaLMoore
Copy link

ShanaLMoore commented Sep 18, 2024

Issue seems to be happening here.

@sjproctor to attach screenshot of params. Form looks as expected before this point. it issue can be see after evaluating 'action', here. "" values should be nil. [ " " ] values should be [ ]

Sarah has a bandaid in place for now but we still need to figure this out because anyone editing/creating a record from the frontend will introduce bad data in the system.

until we can figure out the WHY, maybe we need to clean the params?

#psuedocode
def clean_params(params)
  params.each do |key, value|
    if value.is_a?(ActionController::Parameters)
      clean_params(value) # Recursively clean nested hashes
    elsif value.is_a?(Array)
      params[key] = value == [""] ? [] : value # Convert [""] to []
    else
      params[key] = value.empty? ? nil : value # Convert "" to nil
    end
  end
end

# Call the method on your params
clean_params(params)

@ShanaLMoore ShanaLMoore added the M2 Milestone 2 label Sep 18, 2024
@ShanaLMoore ShanaLMoore changed the title Tech debt: Some form data persisting [""] instead of [] for blank entries Some form data persisting [""] instead of [] for blank entries Sep 18, 2024
@ShanaLMoore ShanaLMoore self-assigned this Sep 19, 2024
@sjproctor
Copy link
Contributor Author

app/samvera/hyrax-webapp/gems/hyrax/app/controllers/concerns/hyrax/works_controller_behavior.rb

  • form looks correct
    Image
  • action looks correct
    Image
  • params are not correct
    Image

@kirkkwang
Copy link
Contributor

In Hyrax the params also get populated with [""] or "", so I'm thinking something is happening in the action

@ShanaLMoore ShanaLMoore removed their assignment Sep 19, 2024
@sjproctor
Copy link
Contributor Author

This problem is being addressed in #771

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M2 Milestone 2 Valkyrie
Projects
None yet
Development

No branches or pull requests

3 participants