gd-bs 6.6.8 → 6.6.10

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.
@@ -82,6 +82,8 @@ var _CheckboxGroup = /** @class */ (function (_super) {
82
82
  }
83
83
  // Render the checkboxes
84
84
  this.renderItems();
85
+ // Set the value
86
+ this.setValue(this.props.value);
85
87
  };
86
88
  // Configure the events
87
89
  _CheckboxGroup.prototype.configureEvents = function (item) {
@@ -129,14 +131,6 @@ var _CheckboxGroup = /** @class */ (function (_super) {
129
131
  label: this.props.label || ""
130
132
  });
131
133
  }
132
- // See if this is a single checkbox
133
- if (this.props.multi != true && items.length > 0) {
134
- // See if this checkbox should be checked
135
- if (typeof (this.props.value) === "boolean" && this.props.value) {
136
- // Select the item
137
- items[0].isSelected = true;
138
- }
139
- }
140
134
  // Parse the items
141
135
  for (var i = 0; i < items.length; i++) {
142
136
  var item = items[i];
@@ -185,6 +179,15 @@ var _CheckboxGroup = /** @class */ (function (_super) {
185
179
  // Method to set the value
186
180
  // Sets the dropdown value
187
181
  _CheckboxGroup.prototype.setValue = function (value) {
182
+ // See if this is a single checkbox
183
+ if (this.props.multi != true && this._checkboxes.length == 1) {
184
+ // See if this checkbox should be checked
185
+ if (typeof (value) === "boolean" && value) {
186
+ // Select the item
187
+ this._checkboxes[0].isChecked ? null : this._checkboxes[0].toggle();
188
+ }
189
+ return;
190
+ }
188
191
  // Ensure it's an array
189
192
  var values = value ? (typeof (value.length) === "number" && typeof (value) !== "string" ? value : [value]) : [];
190
193
  // Parse the items
@@ -377,6 +377,64 @@ 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 value = currentValues[i];
415
+ // Find the item
416
+ var item = (_a = this_1.props.items) === null || _a === void 0 ? void 0 : _a.find(function (item) {
417
+ // Match by the text property if the value doesn't exist
418
+ if (typeof (item.value) === undefined) {
419
+ return item.text == value;
420
+ }
421
+ // See if the value property matches
422
+ return item.value == value;
423
+ });
424
+ // See if an item was found
425
+ if (item) {
426
+ // Add the text property
427
+ values.push(item.text);
428
+ }
429
+ };
430
+ var this_1 = this;
431
+ // Parse the current values
432
+ for (var i = 0; i < currentValues.length; i++) {
433
+ _loop_1(i);
434
+ }
435
+ // Return the values
436
+ return values;
437
+ };
380
438
  // Renders the items
381
439
  _Dropdown.prototype.renderItems = function () {
382
440
  var _this = this;
@@ -387,28 +445,13 @@ var _Dropdown = /** @class */ (function (_super) {
387
445
  if (menu) {
388
446
  // See if we are creating checkboxes
389
447
  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
448
  // Render the checkbox
406
449
  this._cb = (0, checkboxGroup_1.CheckboxGroup)({
407
450
  className: "m-2",
408
451
  el: menu,
409
- items: cbItems,
452
+ items: this.generateCheckboxItems(),
410
453
  multi: this.props.multi,
411
- value: this.props.value,
454
+ value: this.generateCheckboxValue(this.props.value),
412
455
  onChange: this.props.onChange ? function (values, ev) {
413
456
  // Pass the current values
414
457
  _this.props.onChange(_this.getValue(), ev);
@@ -477,7 +520,6 @@ var _Dropdown = /** @class */ (function (_super) {
477
520
  // Add the value
478
521
  values.push(items[i].data);
479
522
  }
480
- // Return the value
481
523
  }
482
524
  else {
483
525
  // Parse the items
@@ -523,7 +565,7 @@ var _Dropdown = /** @class */ (function (_super) {
523
565
  // See if we are rendering checkboxes
524
566
  if (this._cb) {
525
567
  // Set the items
526
- this._cb.setItems(newItems);
568
+ this._cb.setItems(this.generateCheckboxItems());
527
569
  return;
528
570
  }
529
571
  // Get the menu
@@ -575,8 +617,8 @@ var _Dropdown = /** @class */ (function (_super) {
575
617
  _Dropdown.prototype.setType = function (ddlType) {
576
618
  // Parse the element types to search for
577
619
  var elTypes = ["button", ".dropdown-toggle"];
578
- var _loop_1 = function (i) {
579
- var el = this_1.el.querySelector(elTypes[i]);
620
+ var _loop_2 = function (i) {
621
+ var el = this_2.el.querySelector(elTypes[i]);
580
622
  if (el) {
581
623
  // Parse the class names
582
624
  button_1.ButtonClassNames.parse(function (className) {
@@ -588,15 +630,21 @@ var _Dropdown = /** @class */ (function (_super) {
588
630
  className ? el.classList.add(className) : null;
589
631
  }
590
632
  };
591
- var this_1 = this;
633
+ var this_2 = this;
592
634
  for (var i = 0; i < elTypes.length; i++) {
593
- _loop_1(i);
635
+ _loop_2(i);
594
636
  }
595
637
  };
596
638
  // Sets the dropdown value
597
639
  _Dropdown.prototype.setValue = function (value) {
598
640
  // Ensure it's an array
599
641
  var values = value == null ? [] : (typeof (value.length) === "number" && typeof (value) !== "string" ? value : [value]);
642
+ // See if this is a checkbox
643
+ if (this._cb) {
644
+ // Set the value
645
+ this._cb.setValue(this.generateCheckboxValue(value));
646
+ return;
647
+ }
600
648
  // Parse the items
601
649
  for (var i = 0; i < this._items.length; i++) {
602
650
  var item = this._items[i];