(REF) crmUi - Support onCrmUiSelect for using select2 as a picklist #20789
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Add an Angular directive to enrich the behavior of
crm-ui-select
- firing an event immediately after selecting a value (on-crm-ui-select
).It may help to consider an example use-case. The
crmMailingToken
widget presents a pick-list of available tokens:After picking a token, it closes the list and executes some code based on the selected value (adding the selected token to the body of the text editor).
However, the
crmMailingToken
implementation is specific to CiviMail. This patch aims to support message-template-editing for dev/mail#83. The behavior of the widget should be similar, but other key details (like the list of available tokens - and the visual placement of the token widget) can differ.Before
If you want to implement a select2 pick list, your options are:
crm-mailing-token
. But this only supports CiviMail tokens specifically.crm-mailing-token
and then edit in several ways.<select>
widget withcrm-ui-select
,ng-model
, andng-change
. However, this has problematic behavioral quirks, and it also requires defining a superfluous model-field in the scope (which then has to be reset periodically).After
One may use the existing
crm-ui-select
directive and combine it withon-crm-ui-select
, as in:Comments
For a live example, see the WIP extension msgtplui, e.g. https://github.com/totten/msgtplui/blob/34693479354966381c46f1921ed464ac5c9b94a4/ang/msgtplui/EditContent.html#L8-L14. (Note, though, that this may require other patches. This branch integrates tangential requirements.)
It may make sense at some point to phase-out
crmMailingToken
, but that is a different scope of work from enhancingcrmUiSelect
/onCrmUiSelect
.