Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Store the field definition key as the field definition "name" #34

Merged
merged 1 commit into from

2 participants

@grippy

Right now, manual field rendering requires knowing the name of the 'key' being rendered.

Like so: form.field.email.toHTML('email');

This patch removes the 'name' argument from the field.toHTML method.

Like so: form.field.email.toHTML();

Left how the Form calls toHTML alone so this works both ways.

@ljharb ljharb commented on the diff
lib/fields.js
@@ -71,6 +71,7 @@ exports.string = function (opt) {
return r;
};
f.toHTML = function (name, iterator) {
+ name = name || this.name;
@ljharb Collaborator
ljharb added a note

I'd prefer if (!name) { name = this.name; } rather than always doing the assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@ljharb ljharb merged commit a5d9b30 into caolan:master
@ljharb ljharb referenced this pull request from a commit
@ljharb ljharb Pull request #34 cleanup. 60cacc4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 2, 2012
  1. @grippy
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 0 deletions.
  1. +1 −0  lib/fields.js
  2. +3 −0  lib/forms.js
View
1  lib/fields.js
@@ -71,6 +71,7 @@ exports.string = function (opt) {
return r;
};
f.toHTML = function (name, iterator) {
+ name = name || this.name;
@ljharb Collaborator
ljharb added a note

I'd prefer if (!name) { name = this.name; } rather than always doing the assignment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
return (iterator || forms.render.div)(name, this);
};
View
3  lib/forms.js
@@ -12,6 +12,9 @@ exports.render = require('./render');
exports.validators = require('./validators');
exports.create = function (fields) {
+ Object.keys(fields).forEach(function (k) {
+ fields[k].name = k;
+ });
var f = {
fields: fields,
bind: function (data) {
Something went wrong with that request. Please try again.