gd-bs 6.6.9 → 6.6.11

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.
@@ -377,6 +377,74 @@ var _Dropdown = /** @class */ (function (_super) {
377
377
  }
378
378
  }
379
379
  };
380
+ // Generates the checkbox items
381
+ _Dropdown.prototype.generateCheckboxItems = function () {
382
+ var cbItems = [];
383
+ // Parse the items
384
+ var items = this.props.items || [];
385
+ for (var i = 0; i < items.length; i++) {
386
+ var item = items[i];
387
+ // Create the checkbox item
388
+ cbItems.push({
389
+ data: item,
390
+ isDisabled: item.isDisabled,
391
+ isSelected: item.isSelected,
392
+ label: item.text,
393
+ onChange: item.onClick,
394
+ type: checkboxGroup_1.CheckboxGroupTypes.Checkbox
395
+ });
396
+ }
397
+ // Return the items
398
+ return cbItems;
399
+ };
400
+ // Generates the checkbox value
401
+ _Dropdown.prototype.generateCheckboxValue = function (currentValues) {
402
+ var _a;
403
+ var values = [];
404
+ // Ensure a value exists
405
+ if (currentValues == null) {
406
+ return values;
407
+ }
408
+ // Ensure it's an array
409
+ if (typeof (currentValues) === "string") {
410
+ // Make it an array
411
+ currentValues = [currentValues];
412
+ }
413
+ var _loop_1 = function (i) {
414
+ var currentValue = currentValues[i];
415
+ var currentItem = {};
416
+ // See if this is a string
417
+ if (typeof (currentValue) == "string") {
418
+ // Set the text property
419
+ currentItem.text = currentValue;
420
+ }
421
+ else {
422
+ // Set the item
423
+ currentItem = currentValue;
424
+ }
425
+ // Find the item
426
+ var item = (_a = this_1.props.items) === null || _a === void 0 ? void 0 : _a.find(function (item) {
427
+ // Match by the text property if the value doesn't exist
428
+ if (typeof (item.value) === undefined) {
429
+ return item.text == currentItem.text;
430
+ }
431
+ // See if the value property matches
432
+ return item.value == currentItem.value;
433
+ });
434
+ // See if an item was found
435
+ if (item) {
436
+ // Add the text property
437
+ values.push(item.text);
438
+ }
439
+ };
440
+ var this_1 = this;
441
+ // Parse the current values
442
+ for (var i = 0; i < currentValues.length; i++) {
443
+ _loop_1(i);
444
+ }
445
+ // Return the values
446
+ return values;
447
+ };
380
448
  // Renders the items
381
449
  _Dropdown.prototype.renderItems = function () {
382
450
  var _this = this;
@@ -387,28 +455,13 @@ var _Dropdown = /** @class */ (function (_super) {
387
455
  if (menu) {
388
456
  // See if we are creating checkboxes
389
457
  if (this.props.isCheckbox) {
390
- var cbItems = [];
391
- // Parse the items
392
- var items = this.props.items || [];
393
- for (var i = 0; i < items.length; i++) {
394
- var item = items[i];
395
- // Create the checkbox item
396
- cbItems.push({
397
- data: item,
398
- isDisabled: item.isDisabled,
399
- isSelected: item.isSelected,
400
- label: item.text,
401
- onChange: item.onClick,
402
- type: checkboxGroup_1.CheckboxGroupTypes.Checkbox
403
- });
404
- }
405
458
  // Render the checkbox
406
459
  this._cb = (0, checkboxGroup_1.CheckboxGroup)({
407
460
  className: "m-2",
408
461
  el: menu,
409
- items: cbItems,
462
+ items: this.generateCheckboxItems(),
410
463
  multi: this.props.multi,
411
- value: this.props.value,
464
+ value: this.generateCheckboxValue(this.props.value),
412
465
  onChange: this.props.onChange ? function (values, ev) {
413
466
  // Pass the current values
414
467
  _this.props.onChange(_this.getValue(), ev);
@@ -477,7 +530,6 @@ var _Dropdown = /** @class */ (function (_super) {
477
530
  // Add the value
478
531
  values.push(items[i].data);
479
532
  }
480
- // Return the value
481
533
  }
482
534
  else {
483
535
  // Parse the items
@@ -523,7 +575,7 @@ var _Dropdown = /** @class */ (function (_super) {
523
575
  // See if we are rendering checkboxes
524
576
  if (this._cb) {
525
577
  // Set the items
526
- this._cb.setItems(newItems);
578
+ this._cb.setItems(this.generateCheckboxItems());
527
579
  return;
528
580
  }
529
581
  // Get the menu
@@ -575,8 +627,8 @@ var _Dropdown = /** @class */ (function (_super) {
575
627
  _Dropdown.prototype.setType = function (ddlType) {
576
628
  // Parse the element types to search for
577
629
  var elTypes = ["button", ".dropdown-toggle"];
578
- var _loop_1 = function (i) {
579
- var el = this_1.el.querySelector(elTypes[i]);
630
+ var _loop_2 = function (i) {
631
+ var el = this_2.el.querySelector(elTypes[i]);
580
632
  if (el) {
581
633
  // Parse the class names
582
634
  button_1.ButtonClassNames.parse(function (className) {
@@ -588,15 +640,21 @@ var _Dropdown = /** @class */ (function (_super) {
588
640
  className ? el.classList.add(className) : null;
589
641
  }
590
642
  };
591
- var this_1 = this;
643
+ var this_2 = this;
592
644
  for (var i = 0; i < elTypes.length; i++) {
593
- _loop_1(i);
645
+ _loop_2(i);
594
646
  }
595
647
  };
596
648
  // Sets the dropdown value
597
649
  _Dropdown.prototype.setValue = function (value) {
598
650
  // Ensure it's an array
599
651
  var values = value == null ? [] : (typeof (value.length) === "number" && typeof (value) !== "string" ? value : [value]);
652
+ // See if this is a checkbox
653
+ if (this._cb) {
654
+ // Set the value
655
+ this._cb.setValue(this.generateCheckboxValue(value));
656
+ return;
657
+ }
600
658
  // Parse the items
601
659
  for (var i = 0; i < this._items.length; i++) {
602
660
  var item = this._items[i];