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

Disclude blank values from Syphon.serialize #24

Open
SimplGy opened this issue Jun 22, 2013 · 3 comments
Open

Disclude blank values from Syphon.serialize #24

SimplGy opened this issue Jun 22, 2013 · 3 comments

Comments

@SimplGy
Copy link

SimplGy commented Jun 22, 2013

Hi Derick!

I'm looking for where to start on changing the serialize behavior so that blank keys are not included in the object that Syphon returns. would changing the default key extractor be the right place to make this adjustment?

Right now I do this outside of Syphon, but I would like to implement it as an option for this library.

getVals: ->
  formData = Syphon.serialize @el
  # remove field names for blank values
  for field, val of formData
    delete formData[field] unless val
  formData
@jamiebuilds
Copy link
Member

Hi @SimpleAsCouldBe, sorry this wasn't addressed sooner.

I'm tempted to say that this is something that belongs outside of Syphon, but could you provide me a use case for it?

@SimplGy
Copy link
Author

SimplGy commented Apr 23, 2014

It's been a long time since I thought about it. I think this applies to any form that the user might fill in partially, depending on needs. So like a profile screen or similar. If Syphon let me just ignore blank fields instead of including blank values it'd be a better/smaller JSON package.

@rhubarbselleven
Copy link
Contributor

What should Syphon do with blank fields?

If they're included, then when the caller performs a model.set they're potentially going to wipe out some other fields that they're wanting to hold onto. However perhaps that's the desired behaviour.

My thought here is to expand the serialize API to allow for conditional blank key inclusion.

Thoughts?

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

No branches or pull requests

3 participants