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

Individual field rendering? #49

Closed
kokujin opened this issue Jan 30, 2013 · 3 comments
Closed

Individual field rendering? #49

kokujin opened this issue Jan 30, 2013 · 3 comments
Assignees

Comments

@kokujin
Copy link

kokujin commented Jan 30, 2013

I would like to add extra markup and other changes to certain fields in my templates. How can I individually render the fields of a form in my template? Thanks

// Something like this
{% for field in formObj.fields %}
{% if field.widget.type === 'email' %}
... do something else
{% endif %}
{% endfor %}

@ljharb
Copy link
Collaborator

ljharb commented Jan 30, 2013

Can you provide an example of what you intend? The entire purpose of widgets is for that to be the mechanism for customizing a field, instead of having to do it in your template.

@kokujin
Copy link
Author

kokujin commented Jan 30, 2013

I have several forms in my application, but just one template to render them all. I would like to make the changes depend on CSS and markup values in the template than to make the changes in all the forms.

@ljharb
Copy link
Collaborator

ljharb commented Jan 30, 2013

I'm not sure I understand. To render a form using this module, you just call .toHTML() on the form object. If you have a special CSS class you want applied to email fields, then you can make your own email widget that calls the default one, and then extends it with your own CSS classes. Then, the form container in the template's CSS markup can use these form field classes to style things however you like.

Can you provide a JSFiddle that illustrates what you're trying to do? Based on my current understanding, your use case doesn't fit what this module does - ie, the form object should contain knowledge of how to both validate it, and entirely render it. What template it's in doesn't and shouldn't matter.

@ghost ghost assigned ljharb Feb 18, 2013
@ljharb ljharb closed this as completed Apr 29, 2013
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