From c8d508f4de7ca73400b0f774782ef64f338d1a4f Mon Sep 17 00:00:00 2001 From: "fabien.leconte" Date: Fri, 30 Sep 2016 09:40:06 +0200 Subject: [PATCH] New callback to allow user to customize templates. --- assets/scripts/src/choices.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/assets/scripts/src/choices.js b/assets/scripts/src/choices.js index bbc8d16..a4919ed 100644 --- a/assets/scripts/src/choices.js +++ b/assets/scripts/src/choices.js @@ -102,6 +102,7 @@ export default class Choices { callbackOnRemoveItem: null, callbackOnHighlightItem: null, callbackOnUnhighlightItem: null, + callbackOnCreateTemplates: null, callbackOnChange: null, callbackOnSearch: null, }; @@ -2026,7 +2027,15 @@ export default class Choices { }, }; - this.config.templates = templates; + // User's custom templates + const callbackTemplate = this.config.callbackOnCreateTemplates; + let userTemplates = {}; + if (callbackTemplate) { + if (isType('Function', callbackTemplate)) { + userTemplates = callbackTemplate(this, strToEl); + } + } + this.config.templates = extend(templates, userTemplates); } /**