2.0.44 • Published 3 years ago

jvx-multiselect v2.0.44

Weekly downloads
166
License
-
Repository
github
Last release
3 years ago

\<jvx-multiselect>

A web component that offers a multipurpose material multiselect which handles both synchronous and asynchronous selections.

Install jvx-multiselect

npm install jvx-multiselect

API

Slots

NameDescription
option-itemUse this slot to pass a custom template for the options. Use [option.propertyname] to access the property of the item. The template should be styled inline.
optionsIt's one of the way to pass the options to the select: the elements inside the slot shall be divs with a value attribute and a text attribute that are used to define the option.

Properties/Attributes

NameTypeDefaultDescription
advancedSearchBooleanfalseTrue to enable the advanced search (searchInput must be true).
clearableBooleanfalseTrue to enable the empty selection.
closeOnClickBooleanfalseTrue if the options list must be closed on each click outside the component.
disabledBooleanfalseTrue to disable the select.
filterObjectnullThe custom filter for the post call.
flatRoundBooleanfalseWhen true gives the jvx-multiselect a nice flat-rounded appearance.
hasErrosBooleanfalseTrue to display the component in the "error" mode.
httpParametersObjectnullThe custom search value and pagination for the asynchronous selection.
itemTextString'text'The name of the property of the option object that will be displayed as description of the options.
itemValueString'value'The name of the property of the option object that will be treated as value of the options.
placeholderString''The placeholder.
labelString''The label.
labelsObjectnullThe dictionary to map the response.
multiBooleanfalseTrue if it's a multiselect.
optionsArray[]Array of the options in the form of Objects.
requestHeadersObject{...}The headers of the HTTP request.
requestType'GET'|'POST''GET'The type of the HTTP request.
searchInputBooleanfalseTrue to enable the search input for the options list.
searchLabelString'search'The label of the search input.
useOnlyHttpParametersBooleanfalseTrue to ignore the default pagination.
paginatedBooleanfalseTrue if the the response is never paginated.
listPropStringfalseName of the property in response.data where the list is stored.
totalRowsPropStringfalseName of the property in response.data where the number of total rows is stored.
urlString''The url to get the options.
valueArray[]The current value of the selection.

Methods

None

Events

Event NameTargetDetailDescription
inputArrayFired when the user changes the value of the input. The detail contains the value of the selection.
showAdvancedSearchNoneFired when the user clicks on the advanced search icon.
responseObjectFired when the backend call returns successfully. The detail contains the response.
invalid-jwtObjectFired when the backend call returns with an invalit jwt error. The detail contains the response.
errorStringFired when the backend call throws an exception. The detail contains the exception.
scrollEndNoneFired when the scrollbar in the options menu reaches the bottom.
jvx-menu-openeedNoneFired when the the menu is opened.
jvx-menu-closedNoneFired when the the menu is closed.

CSS Custom Properties

None

Global Custom Properties

NameDefaultDescription
--jvx-multiselect-primaryblueColor of the select bottom line when idle.
--jvx-multiselect-accentgreenColor of the underline ripple, the outline, and the caret when active.
--jvx-multiselect-errorredColor of the underline ripple, the outline, and the caret when has errors.
--jvx-multiselect-color#000Color of the text.
--jvx-multiselect-background-color#fffColor of the background of the menu.
--jvx-material-input-height | Height of the select.
--jvx-multiselect-selection-colorcurrentColorColor of the selected value.
--jvx-multiselect-selection-font-size14pxFont size of the selected value.
--jvx-multiselect-selection-font-weight400Font weight of the selected value.
--jvx-multiselect-label-colorcurrentColorColor of the label.
--jvx-multiselect-label-font-size14pxFont size of the label.
--jvx-multiselect-label-font-weight400Font weight of the label.
--jvx-multiselect-placeholder-colorvar(--jvx-multiselect-color)Color of the placeholder.
--jvx-multiselect-placeholder-font-size14pxFont size of the placeholder.
--jvx-multiselect-placeholder-font-weight400Font weight of the placeholder.

HTTP Request

Request

The HTTP request can be either a GET or a POST request. The user can set the type using the property requestType which is set to 'GET' by default.

The HTTP request will be executed via axios.

httpParameters

The parameters for the HTTP request are stored in the property httpParameters. If the property useOnlyHttpParamters is false, a new object will be created which will integrate a copy of httpParameters will be completed as follows:

  Object.assign(httpParametersCopy, {
        search: this.searchValue,
        page: this.pagination.page,
        pageSize: this.pagination.pageSize,
        filter: !!this.filter && (typeof this.filter === 'object' || this.filter.length > 0) ? JSON.stringify(this.filter) : null
      });

This object will be passed in the property data or in the property params of the axios request depending on the HTTP request type.

Headers

The headers can be set in the property requestHeaders. By default the jvx-multiselect uses the property trusted stored in the sessionStorage. The default headers are:

var requestHeaders = {
  'Accept': 'application/json',
  'Access-Control-Allow-Origin': '*',
  'Access-Control-Allow-Methods': 'GET, PUT, POST, DELETE, OPTIONS',
  'Content-Type': 'application/json',
  'Authorization': window.sessionStorage.getItem('trusted')
}

Response

By now the response must contain an array of objects, stored in the property message in the response.data object.

The object template should be

var obj: {
  value: Number|String,
  text: String
}

If the object comes in different form, via the property labels it is possible to set an object that maps the properties in order to make it readable for the jvx-multiselect. For example if the response object template is

var response = {
  id: 1,
  title: 'This is the title',
  description: 'This is the description',
  start: 2020/01/01,
  end: 2020/03/01
}

and the property labels is

var labels = {
  id: 'value',
  title: 'text'
}

the response object will be mapped like this

var response = {
  value: 1,
  text: 'This is the title',
  id: 1,
  title: 'This is the title',
  description: 'This is the description',
  start: 2020/01/01,
  end: 2020/03/01,
  selected: Boolean
}

The user can use the properties itemText and itemValue to prevent the need for the mapping (being in the example above itemText = 'title' and itemValue = 'id').

Search

When the user searches for a term, the property searchInput is updated with the searched value. Its value is then copied in the property search of the object of the search parameters.

Pagination

The property pagination is structured by default as follows:

var pagination = {
  page: 1,
  pageSize: 15
}

Whenever the scrollbar in the menu reaches the bottom, the property page is incremented by one and a further http request is called. When the user searches or closes the menu the property page is set again at 1. The jvx-multiselect copies these values individually in the object of the search parameters.

Slots

option-item

The slot option-item allows to define a template for the options that will be shown in the dropdown menu. It is possible to access the context wrapping it between square brackets. i.e.: Let's say we have the following structure:

var options = [{
  value: 1, 
  text: 'Lorem ipsum',
  color: 'blue',
  preview: 'path/to/first-image.jpg'
},
  {
    value: 2,
    text: 'dolor sit amet',
    color: 'red',
    preview: 'path/to/second-image.jpg'
  }];

and we want our options to have in the text field both the property color and the property text. We can write the template like so:

<div slot="option-item">[[option.text]] [[option.color]]</div>

It's possible to use the context inside attributes too. In that case it's suggested to preppend the string data-jvx- to all the attributes' names that will access the context. i.e.

<div slot="option-item">
    <span>[[option.text]]</span>
    <span>
        <img data-jvx-src="[[option.preview]]"/>
    </span>
</div>

selected-item

This slot works exactly as option-item, but it is used to style the selected value when multi is false.

options

The slot options is there to provide an easy way to describe all the available options of the select. This is necessary because some frameworks may have problems in passing the array to the options prop. Each option will be a div and all the properties of the corresponding object can be written inside an attribute preceded by data-jvx-, like so:

<div slot="options">
    <div value="1" text="Lorem ipsum" data-jvx-color="blue" data-jvx-preview="path/to/first-image.jpg"></div>
    <div value="2" text="dolor sit amet" data-jvx-color="red" data-jvx-preview="path/to/second-image.jpg"></div>
</div>
2.0.44

3 years ago

2.0.42

3 years ago

2.0.43

3 years ago

2.0.37

3 years ago

2.0.38

3 years ago

2.0.36

3 years ago

2.0.39

3 years ago

2.0.40

3 years ago

2.0.41

3 years ago

2.0.35

3 years ago

2.0.33

3 years ago

2.0.34

3 years ago

2.0.31

3 years ago

2.0.32

3 years ago

2.0.30

3 years ago

2.0.28

3 years ago

2.0.29

3 years ago

2.0.26

3 years ago

2.0.27

3 years ago

2.0.25

3 years ago

2.0.24

3 years ago

2.0.23

3 years ago

2.0.19

3 years ago

2.0.22

3 years ago

2.0.20

3 years ago

2.0.21

3 years ago

2.0.16

3 years ago

2.0.17

3 years ago

2.0.18

3 years ago

2.0.15

3 years ago

2.0.14

3 years ago

2.0.13

3 years ago

2.0.12

3 years ago

2.0.11

3 years ago

2.0.10

3 years ago

2.0.9

3 years ago

2.0.8

3 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.0.128

4 years ago

1.0.127

4 years ago

1.0.126

4 years ago

1.0.125

4 years ago

1.0.124

4 years ago

1.0.121

4 years ago

1.0.120

4 years ago

1.0.119

4 years ago

1.0.118

4 years ago

1.0.117

4 years ago

1.0.116

4 years ago

1.0.115

4 years ago

1.0.114

4 years ago

1.0.113

4 years ago

1.0.112

4 years ago

1.0.111

4 years ago

1.0.109

4 years ago

1.0.110

4 years ago

1.0.107

4 years ago

1.0.106

4 years ago

1.0.108

4 years ago

1.0.105

4 years ago

1.0.104

4 years ago

1.0.103

4 years ago

1.0.101

4 years ago

1.0.102

4 years ago

1.0.100

4 years ago

1.0.99

4 years ago

1.0.96

4 years ago

1.0.95

4 years ago

1.0.94

4 years ago

1.0.93

4 years ago

1.0.92

4 years ago

1.0.91

4 years ago

1.0.90

4 years ago

1.0.89

4 years ago

1.0.88

4 years ago

1.0.87

4 years ago

1.0.86

4 years ago

1.0.83

4 years ago

1.0.85

4 years ago

1.0.82

4 years ago

1.0.81

4 years ago

1.0.80

4 years ago

1.0.79

4 years ago

1.0.77

4 years ago

1.0.78

4 years ago

1.0.76

4 years ago

1.0.75

4 years ago

1.0.74

4 years ago

1.0.73

4 years ago

1.0.72

4 years ago

1.0.71

4 years ago

1.0.70

4 years ago

1.0.69

4 years ago

1.0.68

4 years ago

1.0.66

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.62

4 years ago

1.0.63

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.53

4 years ago

1.0.56

4 years ago

1.0.51

4 years ago

1.0.52

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.49

4 years ago

1.0.50

4 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.41

4 years ago

1.0.40

4 years ago

1.0.39

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.35

4 years ago

1.0.33

4 years ago

1.0.34

4 years ago

1.0.26

4 years ago

1.0.30

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.5

4 years ago

1.0.3

4 years ago

0.0.1

4 years ago