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

Add support for some HTML Input attributes #62

Closed
hugooliveirad opened this issue Mar 5, 2015 · 5 comments
Closed

Add support for some HTML Input attributes #62

hugooliveirad opened this issue Mar 5, 2015 · 5 comments

Comments

@hugooliveirad
Copy link

It would be very useful if newforms Field API supported some HTML attributes such as placeholder and disabled. There's any reason this isn't implemented?

@insin
Copy link
Owner

insin commented Mar 5, 2015

I have plans for disabled and hidden, as they affect validation/requiredness and skipping rendering. Eventually, I want to have a way to define rules for those to implement dynamic show/hide/enable/disable.

placeholder is purely about display, though. How about a new core Field property - widgetAttrs - which lets you provide additional attributes for the field's widget without having to completely override it? This could be what's returned by the base Field.prototype.widgetAttrs() instead of the current hardcoded empty object.

@hugooliveirad
Copy link
Author

Yes, widgetAttrs property looks like a great way to do that. Having to completely override the widget to do such a simple thing like adding placeholder ou class is way too complex.

What attrs would we support? This object is merged with NumberField.prototype.widgetAttrs()? (Couldn't analyze the code enough).

Adding this would make it possible to add data- attributes too, although I couldn't find any use case for them inside React.

@insin
Copy link
Owner

insin commented Mar 5, 2015

It would support any attribute you care to pass 😄

Fields add any widget attributes they're going to provide here:

object.extend(widget.attrs, this.widgetAttrs(widget))

Then any attributes provided during rendering, or passed into BoundField when rendering are merged over the top of them here:

return object.extend({}, this.attrs, renderAttrs, kwargAttrs)

This new core field property could also be the basis for allowing people to attach their own event handlers when creating istances of forms, for not much extra work... this could be a more interesting next release than I thought 👍

@hugooliveirad
Copy link
Author

So we could simply add

kwargs.widgetAttrs = kwargs.widgetAttrs || {};
object.extend(kwargs.widgetAttrs, widget.attrs, this.widgetAttrs(widget));

?

@insin insin mentioned this issue Mar 5, 2015
Closed
16 tasks
@insin insin closed this as completed in 9727fff Mar 5, 2015
@hugooliveirad
Copy link
Author

Awesome 👍

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