Skip to content
This repository has been archived by the owner on Apr 30, 2018. It is now read-only.

Commit

Permalink
feat(formlyConfigProvider): Expose field types map from formlyConfigP…
Browse files Browse the repository at this point in the history
…rovider

For a plugin I am writing that renders an inspector showing the current configuration for formly, I
need access to the types that have been registered with formly. This change exposes the map of type
name to type configuration object via a new method on formlyConfigProvider called getTypes().

This is in support of issue #663
  • Loading branch information
pcardune committed Mar 20, 2016
1 parent 4fda1ed commit 2f81ba5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/providers/formlyConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
angular.extend(this, {
setType,
getType,
getTypes,
getTypeHeritage,
setWrapper,
getWrapper,
Expand Down Expand Up @@ -161,6 +162,10 @@ function formlyConfig(formlyUsabilityProvider, formlyErrorAndWarningsUrlPrefix,
}
}

function getTypes() {
return typeMap
}

function getTypeHeritage(parent) {
const heritage = []
let type = parent
Expand Down
13 changes: 11 additions & 2 deletions src/providers/formlyConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ describe('formlyConfig', () => {
})


describe('setType/getType', () => {
let getterFn, setterFn
describe('setType/getType/getTypes', () => {
let getterFn, setterFn, getTypesFn
const name = 'input'
const template = '<input type="{{options.inputType}}" />'
const templateUrl = '/input.html'
Expand All @@ -195,6 +195,7 @@ describe('formlyConfig', () => {
beforeEach(inject(function(formlyConfig) {
getterFn = formlyConfig.getType
setterFn = formlyConfig.setType
getTypesFn = formlyConfig.getTypes
}))

describe('\(^O^)/ path', () => {
Expand All @@ -217,6 +218,14 @@ describe('formlyConfig', () => {
expect(getterFn('type2').templateUrl).to.equal(templateUrl)
})

it('should expose the mapping from type name to config', () => {
setterFn([
{name, template},
{name: 'type2', templateUrl},
])
expect(getTypesFn()).to.eql({[name]: getterFn(name), type2: getterFn('type2')})
})

it('should allow you to set a wrapper as a string', () => {
setterFn({name, template, wrapper})
expect(getterFn(name).wrapper).to.equal(wrapper)
Expand Down

0 comments on commit 2f81ba5

Please sign in to comment.