Control Behaviour
A MultiInput with tokens and suggestions bound to an internal table - the value help for a field that holds many values at once.
Z2UI5_CL_SMP_APP_078
Learn
Control Behaviour
UI5 1.71
The facts
- Repository
- abap2UI5/samples
- Class
Z2UI5_CL_SMP_APP_078- Source file
z2ui5_cl_smp_app_078.clas.abap↗- Category
- Control Behaviour
- Learning path
- Reach outside the view
- Minimum UI5
- 1.71 — the floor abap2UI5 holds its samples to
- In the playground
- runs in the browser, with no system and nothing installed
- Documentation
- abap2ui5.github.io/docs/cookbook/expert_more/value_help ↗
Keywords: multiinput, token, tokens, suggestion, custom, control
Controls it builds
- sap.m.Column
- sap.m.ColumnListItem
- sap.m.Input
- sap.m.MessageStrip
- sap.m.MultiInput
- sap.m.Page
- sap.m.Shell
- sap.m.Table
- sap.m.Text
- sap.m.Token
- sap.ui.core.mvc.View
- z2ui5.cc.MultiInputExt
Read out of the builder chain by the abap2UI5 linter, not from the category this sample is filed under — which is what makes “which samples build one of these” a question the catalogue can answer at all.
Libraries
Run it here
The sample running, in this page — the app on its own, with no editor over it.
Switch to Playground with this code
Nothing is installed and nothing is sent anywhere: the ABAP is compiled to JavaScript in this browser and runs against abap2UI5 itself.
The ABAP
z2ui5_cl_smp_app_078.clas.abap — 116 lines
Click a number to link to a line — shift-click for a range.
Read it on GitHub ↗
" @keywords multiinput token tokens suggestion custom control
" @summary A MultiInput with tokens and suggestions bound to an internal table - the value help for a field that holds many values at once.
" @docs https://abap2ui5.github.io/docs/cookbook/expert_more/value_help
CLASS z2ui5_cl_smp_app_078 DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
TYPES:
BEGIN OF ty_s_token,
key TYPE string,
text TYPE string,
visible TYPE abap_bool,
selkz TYPE abap_bool,
editable TYPE abap_bool,
END OF ty_s_token.
DATA mt_token TYPE STANDARD TABLE OF ty_s_token WITH EMPTY KEY.
DATA mt_tokens_added TYPE STANDARD TABLE OF ty_s_token WITH EMPTY KEY.
DATA mt_tokens_removed TYPE STANDARD TABLE OF ty_s_token WITH EMPTY KEY.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_smp_app_078 IMPLEMENTATION.
METHOD z2ui5_if_app~main.
IF client->check_on_navigated( ).
DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
)->ele( n = `View` ns = `mvc`
)->a( n = `displayBlock` v = `true`
)->a( n = `height` v = `100%`
)->a( n = `xmlns` v = `sap.m`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->a( n = `xmlns:core` v = `sap.ui.core`
)->a( n = `xmlns:z2ui5` v = `z2ui5.cc` ).
view = view->ele( `Shell`
)->ele( `Page`
)->a( n = `title` v = `abap2UI5 - Control Behaviour - MultiInput with Tokens`
)->a( n = `showNavButton` b = client->check_app_prev_stack( )
)->a( n = `navButtonPress` v = client->_event_nav_app_leave( )
)->a( n = `id` v = `page_main` ).
view->tag( `MessageStrip`
)->a( n = `text` v = `The multiinput_ext custom control extends a sap.m.MultiInput so that added and removed ` &&
`tokens are reported back to ABAP, where the token table and the linked list are updated.`
)->a( n = `type` v = `Information`
)->a( n = `showIcon` b = abap_true
)->a( n = `class` v = `sapUiSmallMargin` ).
view->tag( n = `MultiInputExt` ns = `z2ui5`
)->a( n = `MultiInputId` v = `test`
)->a( n = `change` v = client->_event( `UPDATE_BACKEND` )
)->a( n = `addedTokens` v = client->_bind( mt_tokens_added )
)->a( n = `removedTokens` v = client->_bind( mt_tokens_removed ) ).
view->ele( `MultiInput`
)->a( n = `tokens` v = client->_bind( mt_token )
)->a( n = `id` v = `test`
)->ele( `tokens`
)->tag( `Token`
)->a( n = `key` v = `{KEY}`
)->a( n = `text` v = `{TEXT}`
)->a( n = `selected` v = `{SELKZ}`
)->a( n = `visible` v = `{VISIBLE}`
)->a( n = `editable` v = `{EDITABLE}` ).
DATA(tab) = view->ele( `Table`
)->a( n = `items` v = client->_bind( mt_token )
)->a( n = `mode` v = `MultiSelect` ).
tab->ele( `columns`
)->ele( `Column`
)->tag( `Text`
)->a( n = `text` v = `KEY`
)->end(
)->ele( `Column`
)->tag( `Text`
)->a( n = `text` v = `TEXT` ).
tab->ele( `items`
)->ele( `ColumnListItem`
)->a( n = `selected` v = `{SELKZ}`
)->ele( `cells`
)->tag( `Input`
)->a( n = `enabled` v = `{EDITABLE}`
)->a( n = `value` v = `{KEY}`
)->tag( `Input`
)->a( n = `enabled` v = `{EDITABLE}`
)->a( n = `value` v = `{TEXT}` ).
client->view_display( view->stringify( ) ).
ENDIF.
IF client->get_event( ) = `UPDATE_BACKEND`.
LOOP AT mt_tokens_removed INTO DATA(ls_token).
DELETE mt_token WHERE key = ls_token-key.
ENDLOOP.
LOOP AT mt_tokens_added INTO ls_token.
INSERT VALUE #( key = ls_token-key text = ls_token-text visible = abap_true editable = abap_true ) INTO TABLE mt_token.
ENDLOOP.
mt_tokens_removed = VALUE #( ).
mt_tokens_added = VALUE #( ).
ENDIF.
ENDMETHOD.
ENDCLASS.
More in Control Behaviour
- Control Behaviour — Expand a Panel by ID (setExpanded) (A)
- Control Behaviour — Open the PDF Viewer by ID (A)
- Control Behaviour — Switch NavContainer Page by ID (A)
- Control Behaviour — Wizard with Steps (A)
On this page