Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MAJOR] expose defaults and original Template rendering functions #708

Merged
merged 5 commits into from
Oct 29, 2019
Merged

[MAJOR] expose defaults and original Template rendering functions #708

merged 5 commits into from
Oct 29, 2019

Conversation

tinovyatkin
Copy link
Contributor

@tinovyatkin tinovyatkin commented Oct 26, 2019

In most real life use cases for callbackOnCreateTemplates (like #637), consumer actually want to extend original render a little, without fully overwriting it. However, there is no easy way to do that.
This PR exposes original rendering functions as static readonly property Choices.defaults.templates, so, following code will become possible:

const example = new Choices(element, {
  callbackOnCreateTemplates: () => ({
    input: (...args) =>
      Object.assign(Choices.defaults.templates.input.call(this, ...args), {
        type: "email"
      })
  })
});

MAJOR because it moving undocumented userDefaults into Choices.defaults

src/scripts/choices.js Outdated Show resolved Hide resolved
@tinovyatkin tinovyatkin changed the title expose original Template rendering functions [MAJOR] expose defaults and original Template rendering functions Oct 29, 2019
return TEMPLATES;
},
});
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@jshjohnson jshjohnson merged commit 9504cfc into Choices-js:master Oct 29, 2019
@tinovyatkin tinovyatkin deleted the expose-default-templates branch October 29, 2019 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants