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

Wrap field name and prepend w/ string #70

Closed
ericdfields opened this issue Mar 9, 2015 · 2 comments
Closed

Wrap field name and prepend w/ string #70

ericdfields opened this issue Mar 9, 2015 · 2 comments

Comments

@ericdfields
Copy link

A common convention for form field inputs is to name each field as a sort of property to the object class we're modifying, for example <input name="patient[first_name]"> for the First Name input of my Patient form. This is the default for Rails forms, and I've seen it elsewhere too.

I see that you can pass a prefix on the Forms class to prefix our field names — I could generate patient-first_name in this case — but I can't quite pull off that wrapping I'd like. Is this currently possible? Would you take a PR that makes it so if not?

@insin
Copy link
Owner

insin commented Mar 10, 2015

Could use a prefix format string for this similar to autoId, current behaviour would have it defaulting to '{prefix}-{name}'.

Putting that on Form.prototype would allow overriding when extending, or monkeypatching globally.

@ericdfields
Copy link
Author

Passing a nested object to create an object[attribute] relationship also comes to mind.

var SignupForm = forms.Form.extend({
  patient: {
    __mixins__: [PersonForm],
    birth_date: forms.CharField({
        widget: forms.TextInput({attrs: {className: 'datepicker'}})
     })(),
     ...
  }
})

creates <input name="patient[birth_date]" />, etc…

insin added a commit that referenced this issue Mar 10, 2015
@insin insin closed this as completed in 6b3c273 Mar 11, 2015
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

2 participants