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

Default widget attributes #40

Closed
ghost opened this issue Oct 28, 2012 · 3 comments
Closed

Default widget attributes #40

ghost opened this issue Oct 28, 2012 · 3 comments
Assignees

Comments

@ghost
Copy link

ghost commented Oct 28, 2012

forms.create({
    username: forms.fields.string({
      required: true
    })
});

does not result in <input required="true"> in the HTML. While this can be achieved by setting the widget manually after the fact, it seems counter intuitive to me that passing options to the widget requires an extra step.

Changing 17, 98, 119 of lib/fields.js from forms.widgets.___() to forms.widgets.___(opt) provides what is, in my opinion, more intuitive default behavior.

This also requires String(opt[k]).replace(...) in widgets.js:31, to convert "true" and similar into strings.

@ljharb
Copy link
Collaborator

ljharb commented Oct 28, 2012

It sounds like you're just suggesting passing the options hash through to the widget call from the field call?

it'd be required="required" or required - "true" isn't a valid value for a boolean attribute. So yes, it would require a sanitization method to convert the field options into widget options, and that would include translating boolean trues into the attribute name (ie required: true becomes required: "required") and unsetting boolean falses, for all boolean attributes - disabled, selected, checked, required, readonly, and a number of others.

I'll take a look at it soon.

@ghost ghost assigned ljharb Oct 28, 2012
@ljharb
Copy link
Collaborator

ljharb commented Oct 28, 2012

Actually, even better - "opt" should support an "attrs" hash that is explicitly for HTML attributes.

Making HTML5 form validation attributes automatically appear might actually not be the desired behavior, since one can't style form validation errors, and their behavior in browsers varies widely.

@ljharb ljharb closed this as completed in 73b0d51 Oct 28, 2012
@ghost
Copy link
Author

ghost commented Oct 28, 2012

Wow, quick fix.

You're right that my method was not correct - it relied on Firefox and Chrome's robust handling of basically anything you throw at them. Thanks.

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

1 participant