backbone-forms icon indicating copy to clipboard operation
backbone-forms copied to clipboard

Adds 'with' option to schema for specifying the Field object constructor to build the field with

Open patbenatar opened this issue 11 years ago • 3 comments

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.

patbenatar avatar Sep 26 '13 21:09 patbenatar

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 avatar Sep 27 '13 08:09 powmedia

@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.

patbenatar avatar Sep 27 '13 16:09 patbenatar

@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.

patbenatar avatar Sep 27 '13 17:09 patbenatar