jsuites 5.0.15 → 5.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/jsuites.js CHANGED
@@ -5998,6 +5998,8 @@ function Dropdown() {
5998
5998
  onblur: null,
5999
5999
  oninsert: null,
6000
6000
  onbeforeinsert: null,
6001
+ onsearch: null,
6002
+ onbeforesearch: null,
6001
6003
  sortResults: false,
6002
6004
  autofocus: false,
6003
6005
  }
@@ -6808,11 +6810,13 @@ function Dropdown() {
6808
6810
  // Reset results
6809
6811
  obj.results = null;
6810
6812
  // URL
6811
- var url = obj.options.url + (obj.options.url.indexOf('?') > 0 ? '&' : '?') + 'q=' + str;
6812
- // Remote search
6813
- ajax({
6813
+ var url = obj.options.url;
6814
+
6815
+ // Ajax call
6816
+ let o = {
6814
6817
  url: url,
6815
6818
  method: 'GET',
6819
+ data: { q: str },
6816
6820
  dataType: 'json',
6817
6821
  success: function (result) {
6818
6822
  // Reset items
@@ -6839,8 +6843,24 @@ function Dropdown() {
6839
6843
  } else {
6840
6844
  content.style.display = '';
6841
6845
  }
6846
+
6847
+ if (typeof(obj.options.onsearch) === 'function') {
6848
+ obj.options.onsearch(obj, result);
6849
+ }
6842
6850
  }
6843
- });
6851
+ }
6852
+
6853
+ if (typeof(obj.options.onbeforesearch) === 'function') {
6854
+ let ret = obj.options.onbeforesearch(obj, o);
6855
+ if (ret === false) {
6856
+ return;
6857
+ } else if (typeof(ret) === 'object') {
6858
+ o = ret;
6859
+ }
6860
+ }
6861
+
6862
+ // Remote search
6863
+ ajax(o);
6844
6864
  } else {
6845
6865
  // Search terms
6846
6866
  str = new RegExp(str, 'gi');
@@ -12529,7 +12549,7 @@ var sha512_default = /*#__PURE__*/__webpack_require__.n(sha512);
12529
12549
 
12530
12550
  var jSuites = {
12531
12551
  /** Current version */
12532
- version: '5.0.15',
12552
+ version: '5.0.17',
12533
12553
  /** Bind new extensions to Jsuites */
12534
12554
  setExtensions: function(o) {
12535
12555
  if (typeof(o) == 'object') {
@@ -41,7 +41,9 @@ interface Options {
41
41
  // Data type
42
42
  dataType: null,
43
43
  // Controls
44
- controls: true
44
+ controls: boolean,
45
+ /** Auto select confirms the current date as the new value onblur. Default: true */
46
+ autoSelect: boolean;
45
47
  }
46
48
 
47
49
  /** Toast Plugin */
@@ -1,4 +1,4 @@
1
- interface Item {
1
+ interface DropdownItem {
2
2
  /** Value of the selected item. */
3
3
  id?: string | number;
4
4
  /** Label for the selected item. */
@@ -17,62 +17,66 @@ interface Item {
17
17
  color?: string;
18
18
  }
19
19
 
20
- interface Options {
21
- /** Load the data from a remove server URL */
22
- url: string,
23
- /** Load data to the dropdown */
24
- data: Item[],
25
- /** Legacy format { id: name } or { value: text } */
26
- format: number,
27
- /** Accept multiple item selection */
28
- multiple: boolean,
29
- /** Enable the suggestion option */
30
- autocomplete: boolean,
31
- /** Search for an option remotely */
32
- remoteSearch: boolean,
33
- /** Enable the lazyloading option when you are dealing with too much options */
34
- lazyLoading: boolean,
35
- /** Internal type */
36
- type: 'dropdown',
37
- /** Width of the dropdown */
38
- width: number,
39
- /** Max width of the dropdown */
40
- maxWidth: number,
41
- /** Start the dropdown opened */
42
- opened: boolean,
43
- /** Initial value */
44
- value: string,
45
- /** Dropdown place holder */
46
- placeholder: string,
47
- /** Accept the user to add new options */
48
- newOptions: boolean,
49
- /** Internal position controller. */
50
- position: boolean,
51
- /** When the value chnaged */
52
- onchange: () => void,
53
- /** When the dropdown is ready */
54
- onload: () => void,
55
- /** When the dropdown is opened */
56
- onopen: () => void,
57
- /** When the dropdown is closed */
58
- onclose: () => void,
59
- /** When the dropdown is focused */
60
- onfocus: () => void,
61
- /** When the dropdown is blur */
62
- onblur: () => void,
63
- /** When the user add a new option to the dropdown. */
64
- oninsert: () => void,
65
- /** Just before a new option is added to the dropdown */
66
- onbeforeinsert: () => void,
67
- /** Sort the elements of the dropdown */
68
- sortResults: boolean,
69
- /** Focus when the dropdown is created */
70
- autofocus: boolean,
20
+ interface DropdownOptions {
21
+ /** Endpoint to fetch data from a remote server */
22
+ url?: string;
23
+ /** Preloaded data items for the dropdown */
24
+ data?: DropdownItem[];
25
+ /** Format type of the data, typically { id: name } or { value: text } */
26
+ format?: number;
27
+ /** Indicates if multiple item selection is allowed */
28
+ multiple?: boolean;
29
+ /** Enables the autocomplete feature for user input */
30
+ autocomplete?: boolean;
31
+ /** Allows remote search for options */
32
+ remoteSearch?: boolean;
33
+ /** Enables the lazy loading feature for handling a large number of options */
34
+ lazyLoading?: boolean;
35
+ /** Rendering style of the dropdown: 'default', 'picker', or 'searchbar' */
36
+ type?: 'default' | 'picker' | 'searchbar',
37
+ /** Defines the dropdown's width */
38
+ width?: number;
39
+ /** Sets the maximum width of the dropdown */
40
+ maxWidth?: number;
41
+ /** Determines if the dropdown is opened when initialized */
42
+ opened?: boolean;
43
+ /** The initial value of the dropdown */
44
+ value?: string;
45
+ /** Placeholder text for the dropdown */
46
+ placeholder?: string;
47
+ /** Allows the user to add new options */
48
+ newOptions?: boolean;
49
+ /** Internal controller for the dropdown's position */
50
+ position?: boolean;
51
+ /** Event handler for value changes */
52
+ onchange?: (el: HTMLElement, obj: Dropdown, oldValue: string, newValue: string) => void;
53
+ /** Event handler for when the dropdown is ready */
54
+ onload?: (el: HTMLElement, obj: Dropdown, data: any, val: any) => void;
55
+ /** Event handler for when the dropdown opens */
56
+ onopen?: (el: HTMLElement) => void;
57
+ /** Event handler for when the dropdown closes */
58
+ onclose?: (el: HTMLElement) => void;
59
+ /** Event handler for when the dropdown receives focus */
60
+ onfocus?: (el: HTMLElement) => void;
61
+ /** Event handler for when the dropdown loses focus */
62
+ onblur?: (el: HTMLElement) => void;
63
+ /** Event handler for when a new option is added to the dropdown */
64
+ oninsert?: (obj: Dropdown, item: DropdownItem, newItem: DropdownItem) => void;
65
+ /** Event handler for just before a new option is added to the dropdown */
66
+ onbeforeinsert?: (obj: Dropdown, item: DropdownItem) => void;
67
+ /** Event handler for before a search on autocomplete is performed */
68
+ onbeforesearch?: (obj: Dropdown, ajaxRequest: object) => boolean | null;
69
+ /** Event handler for processing search results */
70
+ onsearch?: (obj: Dropdown, result: object) => void;
71
+ /** Toggles the sorting of dropdown elements */
72
+ sortResults?: boolean;
73
+ /** Indicates if the dropdown should automatically receive focus upon creation */
74
+ autofocus?: boolean;
71
75
  }
72
76
 
73
77
  interface ItemContainer {
74
78
  /** Data for the item */
75
- data: Item;
79
+ data: DropdownItem;
76
80
  /** HTML container for the element */
77
81
  element: HTMLElement;
78
82
  /** HTML container for the group */
@@ -80,11 +84,11 @@ interface ItemContainer {
80
84
  }
81
85
 
82
86
  /** Toast Plugin */
83
- export type Dropdown = (el: HTMLElement, options: Options) => {
87
+ export type Dropdown = (el: HTMLElement, options: DropdownOptions) => {
84
88
  /** Add a new item to the dropdown */
85
- add: (title: string, id: string|number) => Item;
89
+ add: (title: string, id: string|number) => DropdownItem;
86
90
  /** Append new data to the dropdown */
87
- appendData: (data: Item[]) => void
91
+ appendData: (data: DropdownItem[]) => void
88
92
  /** Close the dropdown picker */
89
93
  closeItem: (ignoreEvents?: boolean) => void
90
94
  /** Current selectIndex */
@@ -94,7 +98,7 @@ export type Dropdown = (el: HTMLElement, options: Options) => {
94
98
  /** Select the first item */
95
99
  first: () => void;
96
100
  /** Get all data */
97
- getData: () => Item[];
101
+ getData: () => DropdownItem[];
98
102
  /** Get the index position of a item by its value */
99
103
  getPosition: (value: string) => number | boolean;
100
104
  /** Get the text from the selected options */
@@ -124,7 +128,7 @@ export type Dropdown = (el: HTMLElement, options: Options) => {
124
128
  /** Open the dropdown */
125
129
  open: () => void;
126
130
  /** Dropdown configuration */
127
- options: Options;
131
+ options: DropdownOptions;
128
132
  /** Move index to the previous element in the dropdown */
129
133
  prev: () => void;
130
134
  /** Reset the value of the dropdown */
@@ -134,21 +138,21 @@ export type Dropdown = (el: HTMLElement, options: Options) => {
134
138
  /** Set the value to null */
135
139
  resetSelected: () => void;
136
140
  /** Array of results when filtering */
137
- results: Item[];
141
+ results: DropdownItem[];
138
142
  /** Search term */
139
143
  search: string;
140
144
  /** Select an index */
141
145
  selectIndex: (index: number, force?: boolean) => void
142
146
  /** Select an item */
143
- selectItem: (item: Item) => void;
147
+ selectItem: (item: DropdownItem) => void;
144
148
  /** Set the cursor to a specified element index */
145
149
  setCursor: (index: number, setPosition?: boolean) => void
146
150
  /** Set new data for the dropdown */
147
- setData: (items: Item[]) => void;
151
+ setData: (items: DropdownItem[]) => void;
148
152
  /** Set the id or value for one item */
149
- setId: (item: number|Item, newId: number) => void;
153
+ setId: (item: number|DropdownItem, newId: number) => void;
150
154
  /** Change the dropdown options */
151
- setOptions: (newOptions: Options, reset?: boolean) => void;
155
+ setOptions: (newOptions: DropdownOptions, reset?: boolean) => void;
152
156
  /** Change the dropdown data from a URL */
153
157
  setUrl: (newUrl: string, callback?: Function) => void;
154
158
  /** Set the value for a dropdown */
@@ -1,16 +1,25 @@
1
1
  interface Options {
2
- // Validation type
3
- type: 'url' | 'email' | 'required' | 'empty' | 'notEmpty' | 'number' | 'login' | 'list' | 'date' | 'text' | 'textLength'
2
+ /** Validation type */
3
+ type: 'number' | 'text' | 'date' | 'list' | 'textLength' | 'empty' | 'notEmpty';
4
4
  // Ignore the validation when is blank
5
5
  allowBlank?: boolean;
6
- // Criteria
7
- criteria: string
6
+ /** Criteria to be match */
7
+ criteria:
8
+ | '='
9
+ | '!='
10
+ | '>='
11
+ | '>'
12
+ | '<='
13
+ | '<'
14
+ | 'between'
15
+ | 'not between'
16
+ | 'valid date'
17
+ | 'valid email'
18
+ | 'valid url'
19
+ | 'contains'
20
+ | 'not contains'
21
+ | 'begins with'
22
+ | 'ends with'
8
23
  }
9
24
 
10
- interface Number {
11
- criteria: 'between' | 'not between' | '<' | '<=' | '>' | '>=' | '=' | '!='
12
- }
13
-
14
- export type Validations = (value: string | number, options) => {
15
-
16
- }
25
+ export type Validations = (value: string | number, options: Options) => boolean;
package/package.json CHANGED
@@ -25,7 +25,7 @@
25
25
  },
26
26
  "main": "dist/jsuites.js",
27
27
  "types": "dist/jsuites.d.ts",
28
- "version": "5.0.15",
28
+ "version": "5.0.17",
29
29
  "bugs": "https://github.com/jsuites/jsuites/issues",
30
30
  "homepage": "https://github.com/jsuites/jsuites",
31
31
  "docs": "https://jsuites.net",