scientist-softserv / adventist_knapsack

Apache License 2.0
2 stars 0 forks source link

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

Closed sjproctor closed 1 month ago

sjproctor commented 2 months ago

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:

Acceptance Criteria

Testing Instructions

Notes

This appears to happen most often on data values. Ref: https://github.com/scientist-softserv/adventist_knapsack/issues/771

sjproctor commented 1 month ago

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

ShanaLMoore commented 1 month ago

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)
sjproctor commented 1 month ago

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

kirkkwang commented 1 month ago

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

sjproctor commented 1 month ago

This problem is being addressed in https://github.com/scientist-softserv/adventist_knapsack/issues/771