backbone-forms
backbone-forms copied to clipboard
Adds 'with' option to schema for specifying the Field object constructor to build the field with
Sometimes certain fields in a form require custom logic. This allows you to use different Field constructors for different fields in the schema using a with
option like so:
schema: {
name: {
title: "Full Name",
with: MyCoolNameField
}
}
Thoughts? If this is something we'd like to merge, I'd be happy to add tests.
I like the idea; I wonder if with
is the right word though. Something more self-documenting/more obvious might work better. Maybe field
or fieldType
if that doesn't conflict with anything else?
Would be great if you could add tests too.
@powmedia Fair enough.. I spend a lot of time in Rubyland where method calls and options lists read like sentences. I vote for field
as the option name. :+1:
Will push tests up when I have a moment.
@powmedia Added tests and defaulted options.schema
in createField
to an empty object if undefined. A test was failing because of an undefined field schema—I don't imagine this is a common real world use case but figured defaulting was a safe bet. Let me know if you have a better idea here.
Sorry about the whitespace changes littering the commit, my editor strips trailing whitespace—I can fix that if it's a problem.