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

Fixed up serializeArray() and added multiple support #631

Closed

Conversation

twolfson
Copy link
Contributor

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 like serialize (#69). In this PR:

@coveralls
Copy link

Coverage Status

Coverage increased (+0.03%) when pulling 817f84e on underdogio:dev/add.serialize.array.sqwished into f864e39 on cheeriojs:master.

@fb55
Copy link
Member

fb55 commented Jan 24, 2015

@twolfson Thanks for picking this up from @jlep!

Some notes:

  • Please be more generous with white space.
  • It's nice to point to sources, but that can be part of the commit message. While a single source as part of a comment is still fine, you've overdone it a bit.
  • Please add comments instead regarding the function of code. Keep in mind that the code needs to be maintained indefinitely once this pull request is merged, and you might not be around to explain it.
  • Please remove dead code (instead of commenting it out).

var $elem = Cheerio(elem);
var name = $elem.attr('name');
var val = $elem.val();
return val == null ?
Copy link
Member

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.

Copy link
Contributor Author

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.

@twolfson
Copy link
Contributor Author

Have you considered adding jscs to enforce whitespace? I have found it very useful on all of my projects (usually no back and forth about stylistic issues).

http://jscs.info/rules.html

I prefer to leave sources inline since the references to the original code can fade away as more touches occur and git blame erodes. However, I will respect your request.

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')
Copy link
Member

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.

Copy link
Contributor Author

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.

@twolfson twolfson force-pushed the dev/add.serialize.array.sqwished branch from 817f84e to a007441 Compare January 24, 2015 21:57
@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 98.23% when pulling a007441 on underdogio:dev/add.serialize.array.sqwished into e83b10b on cheeriojs:master.

@twolfson
Copy link
Contributor Author

Alright, I have renamed the file so unfortunately most of the inline comments have gone away. I have addressed all of them.

@twolfson twolfson force-pushed the dev/add.serialize.array.sqwished branch from a007441 to 196b2d0 Compare January 24, 2015 22:01
@twolfson
Copy link
Contributor Author

I have re-pushed the branch because Travis CI choked on node@0.11 for some reason.

@twolfson
Copy link
Contributor Author

Ah, never mind it isn't me. It looks like master is having a build error.

@fb55
Copy link
Member

fb55 commented Feb 2, 2015

At this point I would be okay with merging this.

The code would be much simpler when using the :matches selector, but that's something I'll need to implement.

@twolfson
Copy link
Contributor Author

twolfson commented Feb 2, 2015

Sweet, I see that master has been patched. I am going to wiggle my PR build.

@twolfson twolfson force-pushed the dev/add.serialize.array.sqwished branch 3 times, most recently from 96177ef to 30bce68 Compare February 3, 2015 00:02
@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 98.23% when pulling 30bce68 on underdogio:dev/add.serialize.array.sqwished into 64fe78e on cheeriojs:master.

@twolfson
Copy link
Contributor Author

twolfson commented Feb 3, 2015

Alright, the PR has been wiggled and Travis CI is now green.

@jugglinmike
Copy link
Member

I think this is almost there; it's just missing one piece of functionality that I can see. From the jQuery docs:

This method can act on a jQuery object that has selected individual form controls, such as <input>, <textarea>, and <select>.

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

@twolfson
Copy link
Contributor Author

twolfson commented Mar 1, 2015

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.

@jugglinmike
Copy link
Member

That's some stick-to-itiveness for you! Thanks :)

@twolfson twolfson force-pushed the dev/add.serialize.array.sqwished branch from 30bce68 to 7a03e15 Compare March 1, 2015 03:38
@twolfson
Copy link
Contributor Author

twolfson commented Mar 1, 2015

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.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 98.61% when pulling 7a03e15 on underdogio:dev/add.serialize.array.sqwished into 55f7ac0 on cheeriojs:master.

return $elem.filter(submittableSelector).toArray();
}
})
.filter(function() {
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, sure thing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@twolfson twolfson force-pushed the dev/add.serialize.array.sqwished branch from 7a03e15 to 08f2771 Compare March 1, 2015 03:59
@coveralls
Copy link

Coverage Status

Coverage increased (+0.04%) to 98.61% when pulling 08f2771 on underdogio:dev/add.serialize.array.sqwished into 55f7ac0 on cheeriojs:master.

@jugglinmike jugglinmike mentioned this pull request Mar 1, 2015
@jugglinmike
Copy link
Member

Rebased and merged to master via gh-669. Thanks for sticking with us, Todd!

@twolfson
Copy link
Contributor Author

twolfson commented Mar 1, 2015

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.

@twolfson twolfson deleted the dev/add.serialize.array.sqwished branch March 1, 2015 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants