-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fixed up serializeArray()
and added multiple support
#631
Fixed up serializeArray()
and added multiple support
#631
Conversation
…rray Conflicts: lib/cheerio.js
@twolfson Thanks for picking this up from @jlep! Some notes:
|
var $elem = Cheerio(elem); | ||
var name = $elem.attr('name'); | ||
var val = $elem.val(); | ||
return val == null ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be much more readable in an if / else
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was directly from jQuery. I will break it up.
Have you considered adding I prefer to leave sources inline since the references to the original code can fade away as more touches occur and Most of this code is copy/paste from jQuery but I will do my best to document it. As for the inline dead code, that was also inline from jQuery but I will make a comment note instead. |
@@ -13,7 +13,8 @@ var api = [ | |||
require('./api/attributes'), | |||
require('./api/traversing'), | |||
require('./api/manipulation'), | |||
require('./api/css') | |||
require('./api/css'), | |||
require('./api/serialize') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you rename the new source file to "forms.js"? This matches jQuery's documented category scheme and will make a logical home for the serializeArray
function in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure thing. This was originally named api.serialize.js
by @jlep so I tried to keep it as consistent as possible.
817f84e
to
a007441
Compare
Alright, I have renamed the file so unfortunately most of the inline comments have gone away. I have addressed all of them. |
a007441
to
196b2d0
Compare
I have re-pushed the branch because Travis CI choked on |
Ah, never mind it isn't me. It looks like |
At this point I would be okay with merging this. The code would be much simpler when using the |
Sweet, I see that |
96177ef
to
30bce68
Compare
Alright, the PR has been wiggled and Travis CI is now green. |
I think this is almost there; it's just missing one piece of functionality that I can see. From the jQuery docs:
That means before we land this, the patch should be updated to pass a test like: + it('() :', function() {
+ expect($('#nested input').serializeArray()).to.eql([
+ { name: 'fruit', value: 'Apple' },
+ { name: 'vegetable', value: 'Carrot' }
+ ]);
+ }); @twolfson It's been a while since anybody gave you feedback on this. If you'd moved on to bigger and better things, just let me know and I'll be happy to finish this up for ya |
Sure thing. I have a bit of time to kill before heading out tonight. I will take a shot at those new tests and comment when this PR is updated. |
That's some stick-to-itiveness for you! Thanks :) |
30bce68
to
7a03e15
Compare
Alright, I have added a new test and fix. I also saw that the tests are very unclear about what results should be. I have refactored them to be much more about asserting deep equals of arrays/objects to make the return value more obvious. |
return $elem.filter(submittableSelector).toArray(); | ||
} | ||
}) | ||
.filter(function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you move this method call to the previous line for visual consistency in the chain?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, sure thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
7a03e15
to
08f2771
Compare
Rebased and merged to |
Woot, no problem. Glad to see it got landed. There was also the follow-up PR #632 which I will update in a bit to have a much cleaner git history. |
Fixes #235
PR #235 has been open for a while and stagnated. This PR revives adding
serializeArray()
support and establishes a foundation for other form methods likeserialize
(#69). In this PR: