@ministryofjustice/hmpps-digital-prison-reporting-frontend 3.34.1 → 3.34.2

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.
@@ -376,13 +376,13 @@ class DprQueryParamClass extends DprClientClass {
376
376
  } else {
377
377
  const { name } = input;
378
378
  let { value } = input;
379
- let { staticOptionValue } = input;
379
+ let { staticOptionNameValue } = input;
380
380
  let isDateInput = input.classList.contains('moj-js-datepicker-input');
381
381
  if (isDateInput) {
382
382
  const formatted = dayjs(value, 'D/M/YYYY').format('YYYY-MM-DD');
383
383
  value = formatted !== 'Invalid Date' ? formatted : '';
384
384
  }
385
- let valueToUpdate = !isDateInput && staticOptionValue ? staticOptionValue : value;
385
+ let valueToUpdate = !isDateInput && staticOptionNameValue ? staticOptionNameValue : value;
386
386
  if (name) this.updateQueryParam(name, valueToUpdate);
387
387
  }
388
388
  }
@@ -1009,8 +1009,8 @@ class Filters extends DprClientClass {
1009
1009
  const formData = new FormData(filtersForm);
1010
1010
  let serializedFormData = '';
1011
1011
  document.querySelectorAll('.autocomplete-text-input-box').forEach((input) => {
1012
- if(input.staticOptionValue) {
1013
- formData.set(input.name, input.staticOptionValue);
1012
+ if(input.staticOptionNameValue) {
1013
+ formData.set(input.name, input.staticOptionNameValue);
1014
1014
  }
1015
1015
  });
1016
1016
  formData.forEach((v, n) => {
@@ -1538,7 +1538,8 @@ class Autocomplete extends DprClientClass {
1538
1538
  this.getElement()
1539
1539
  .querySelectorAll(this.listItemsSelector)
1540
1540
  .forEach((item) => {
1541
- if (searchValue.length >= minLength && item.innerText.trim().toLowerCase().includes(searchValue)) {
1541
+ if (searchValue.length >= minLength &&
1542
+ this.isMatchingStaticOptionNameOrDisplayPrefix(this.getInputListButton(item), searchValue, item)) {
1542
1543
  item.classList.remove('autocomplete-text-input-item-hide');
1543
1544
  } else {
1544
1545
  item.classList.add('autocomplete-text-input-item-hide');
@@ -1552,6 +1553,19 @@ class Autocomplete extends DprClientClass {
1552
1553
  }
1553
1554
  }
1554
1555
 
1556
+ getInputListButton(item) {
1557
+ return item.querySelector('.autocomplete-text-input-list-button')
1558
+ }
1559
+
1560
+ isMatchingStaticOptionNameOrDisplayPrefix(inputListButton, searchValue, item) {
1561
+ return this.isStaticOptionsNamePrefix(inputListButton.dataset.staticOptionNameValue, searchValue)
1562
+ || item.innerText.trim().toLowerCase().startsWith(searchValue)
1563
+ }
1564
+
1565
+ isStaticOptionsNamePrefix(staticOptionNameValue, searchValue) {
1566
+ return staticOptionNameValue && staticOptionNameValue.trim().toLowerCase().startsWith(searchValue)
1567
+ }
1568
+
1555
1569
  async populateOptionsDynamically(resourceEndpoint, searchValue, textInput, templateProvider) {
1556
1570
  try {
1557
1571
  const response = await fetch(resourceEndpoint.replace('{prefix}', encodeURI(searchValue)));
@@ -1575,7 +1589,7 @@ class Autocomplete extends DprClientClass {
1575
1589
  event.preventDefault();
1576
1590
  // eslint-disable-next-line no-param-reassign
1577
1591
  textInput.value = event.target.innerText.trim();
1578
- textInput.staticOptionValue = event.target.dataset.staticOptionValue;
1592
+ textInput.staticOptionNameValue = event.target.dataset.staticOptionNameValue;
1579
1593
  textInput.focus();
1580
1594
  const changeEvent = new Event('change');
1581
1595
  textInput.dispatchEvent(changeEvent);
@@ -69,7 +69,7 @@
69
69
  classes: "govuk-button--inverse autocomplete-text-input-list-button",
70
70
  attributes: {
71
71
  "data-parent-input": options.id,
72
- "data-static-option-value": item.value
72
+ "data-static-option-name-value": item.value
73
73
  }
74
74
  }) }}
75
75
  </li>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ministryofjustice/hmpps-digital-prison-reporting-frontend",
3
3
  "description": "The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.",
4
- "version": "3.34.1",
4
+ "version": "3.34.2",
5
5
  "main": "dpr/assets/js/all.mjs",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {
package/package.zip CHANGED
Binary file