Skip to content

Commit

Permalink
fix: define icon() on templateControl
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasnetau committed Oct 23, 2023
1 parent cacf5a8 commit 9364525
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/js/customControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default class customControls {
}
templateControl.definition = {}
templateControl.label = type => _this.label(type)
templateControl.icon = type => _this.icon(type)
this.templateControlRegister[templateName] = templateControl
})

Expand Down
29 changes: 29 additions & 0 deletions tests/control/custom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,33 @@ describe('Test Custom Control', () => {
expect(renderedCtl.eq(1).attr('type')).toBe('text')
expect(renderedCtl.eq(1).attr('id')).toMatch(new RegExp('^text-.*'))
})

test('custom control with no icon', async () => {
const fbWrap = $('<div>')
const fields = [
{
className: 'form-control custom-class',
label: 'Custom Text Field',
type: 'customText',
//icon: '🔢'
},
]
const templates = {
customText: function(fieldData) {
return {
field: this.markup('input', null, fieldData)
}
},
}

const fb = await $(fbWrap).formBuilder({fields, templates, }).promise
const field = {
type: 'customText',
className: 'form-control api-class',
value: 'Added by API',
}
fb.actions.addField(field)

expect(fbWrap.find('.stage-wrap li')).toHaveLength(1)
})
})

0 comments on commit 9364525

Please sign in to comment.