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

Single-valued attributes are stored as empty strings after form submission #2296

Closed
little9 opened this issue Dec 3, 2017 · 4 comments
Closed
Labels
Milestone

Comments

@little9
Copy link
Contributor

little9 commented Dec 3, 2017

Descriptive summary

When a work has single-valued attributes and the form is submitted, empty strings are stored.

Rationale

Having these values change after form submission means that views and other code that exports them has to check for nil and an empty string. It would cleaner for the values to remain nil unless they aren't an empty string.

Expected behavior

The value of the single-valued attribute is nil until it becomes a non-empty string.

Actual behavior

The value of blank single-valued attribute become "" after submitted the work form.

Steps to reproduce the behavior

  1. Create a work that has a single-valued attribute
  2. Submit a form for the work
  3. Check the attribute:
work.single_value
""

or view the show page:

screen shot 2017-12-02 at 2 13 44 pm

Related work

curationexperts/epigaea#331
curationexperts/epigaea#618

@jcoyne
Copy link
Member

jcoyne commented Dec 4, 2017

See #2297 (comment)

@jcoyne jcoyne closed this as completed Dec 4, 2017
@dchandekstark dchandekstark reopened this Mar 20, 2018
@dchandekstark
Copy link
Member

The code referenced by @jcoyne does not clean single-valued fields in the desired way -- i.e., cleaning '' to nil.

irb(main):008:0> foo = ''
=> ""
irb(main):009:0> foo.delete('')
=> ""
irb(main):010:0> foo
=> ""

@dchandekstark
Copy link
Member

The fix for https://github.com/samvera/hydra-editor/blob/master/app/forms/hydra_editor/form.rb#L60-L62 could be something like:

terms.each do |key|
  if multiple?(key)
    clean_params[key].delete('') # also compact?
  elsif clean_params[key] == ''
    clean_params[key] = nil
  end
end

@no-reply
Copy link
Contributor

This will be fixed upon support of hydra-editor 4.0.0.

@jrgriffiniii are there blockers to a 4.0.0 release?

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 a pull request may close this issue.

4 participants