powmedia / backbone-forms

Form framework for BackboneJS with nested forms, editable lists and validation
MIT License
2.17k stars 413 forks source link

Adding a 'passwordConfirm' element for match validation throws .render() error. #258

Closed Routhinator closed 11 years ago

Routhinator commented 11 years ago

I'm trying to get a match validator working in my sign-up form. I've added the example:

password: { validators: [ { type: 'match', field: 'passwordConfirm', message: 'Passwords must match!' } ]}

and in my template:

<div data-fields="password">
    <div class="notes">Must be at least 7 characters:</div>
</div>

<div data-fields="passwordConfirm"></div>

However adding the 'passwordConfirm' field breaks render as Backbone.Form seems to have no idea what to do with passwordConfirm - If I remove 'passwordConfirm' the form renders however match validation cannot possibly work as there is no confirmation field.

Routhinator commented 11 years ago

Exact error when 'passwordConfirm' is present in template:

Uncaught TypeError: Cannot call method 'render' of undefined

powmedia commented 11 years ago

Have you added passwordConfirm to your schema alongside password?

On 5 Jul 2013, at 17:24, Chris Routh notifications@github.com wrote:

I'm trying to get a match validator working in my sign-up form. I've added the example:

password: { validators: [ { type: 'match', field: 'passwordConfirm', message: 'Passwords must match!' } ]}

and in my template:

Must be at least 7 characters:

However adding the 'passwordConfirm' field breaks render as Backbone.Form seems to have no idea what to do with passwordConfirm - If I remove 'passwordConfirm' the form renders however match validation cannot possibly work as there is no confirmation field.

— Reply to this email directly or view it on GitHub.

Routhinator commented 11 years ago

I wondered about that but it wasn't in the example and it seemed nonsensical to add something to the schema that doesn't exist in the JSON model, I was expecting errors if I did that.

Just tried that and it's resolved it.

powmedia commented 11 years ago

Yes it does seem out of place on the model schema but you can specify the schema on the form itself (or extend the models schema before adding it to the form) if you want to keep it more semantic.

On 5 Jul 2013, at 18:01, Chris Routh notifications@github.com wrote:

I wondered about that but it wasn't in the example and it seemed nonsensical to add something to the schema that doesn't exist in the JSON model, I was expecting errors if I did that.

Just tried that and it's resolved it.

— Reply to this email directly or view it on GitHub.