-
Notifications
You must be signed in to change notification settings - Fork 352
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
Allow dashes in element names #6
Comments
Thanks for submitting this bug. I'm going to build some unit tests to ensure functionality of the plugin first, then I'll do an iteration that closes out this issue for |
Likewise, for allowing dots in element names. Swapping out the dashes in the regex above with dots seems to do the trick. |
👍 |
Any progress on this? I just applied this "patch" to my forked version and have been using it on some heavily nested complex form items with no hiccups :) |
Hey everyone, I've made some improvements to the plugin over the last couple of days. For now, I think I'm going to leave the regexp patterns the way they are, but I've exposed them so you can customize them in your own apps. This pleases everyone because you can hack them up to have the plugin behave however you like. I've made this decision to keep it easy to access the object returned from the plugin. For example <input name="foo" value="a"> allows us to access the serialized object as <input name="foo-bar" value="a"> would require us to use For those looking for the simple addition of hyphens ( I'll also paste the API amendment here FormSerializer.patterns — modify the patterns used to match field Many of you have requested to allow // example: allow hyphen in keys
$.extend(FormSerializer.patterns, {
validate: /^[a-z][a-z0-9_-]*(?:\[(?:\d*|[a-z0-9_-]+)\])*$/i,
key: /[a-z0-9_-]+|(?=\[\])/gi,
named: /^[a-z0-9_-]+$/i
}); Validating and Key parsing
Key styles
If anyone needs additional support, I will be happy to help out. |
Currently the function excludes any elements in the form that contain a dash in the name attribute, however using dashes are completely valid according the the W3C spec.
To include elements with dashed names in the returned object, I just updated the
patterns.validate
,patterns.key
, andpatterns.named
regular expressions to include a dash in their character sets resulting in the following:The text was updated successfully, but these errors were encountered: