@elite.framework/ng.core 1.0.15 → 1.0.16

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.
@@ -3744,16 +3744,6 @@ class GenericSelectorTypeComponent extends FieldType {
3744
3744
  this.injector = injector;
3745
3745
  this.cdr = cdr;
3746
3746
  }
3747
- onSelectionChange(val) {
3748
- this.selectedItem = val;
3749
- const vf = this.to['valueField'] || 'id';
3750
- if (this.to['multiple']) {
3751
- this.formControl.setValue(Array.isArray(val) ? val.map((c) => c[vf]) : []);
3752
- }
3753
- else {
3754
- this.formControl.setValue(val?.[vf] ?? null);
3755
- }
3756
- }
3757
3747
  ngOnInit() {
3758
3748
  this.api = this.svc;
3759
3749
  this.dialog = this.injector.get(DialogService);
@@ -3813,6 +3803,44 @@ class GenericSelectorTypeComponent extends FieldType {
3813
3803
  this.valueChangeSubscription.unsubscribe();
3814
3804
  }
3815
3805
  }
3806
+ loadDefaultValue() {
3807
+ this.loading = true;
3808
+ const defaultFilter = { isDefault: true };
3809
+ const vf = this.to['valueField'] || 'id';
3810
+ this.api.getList(defaultFilter)
3811
+ .subscribe({
3812
+ next: (res) => {
3813
+ // Assuming the API returns a list and you want to select the first one
3814
+ if (res && res.data && res.data.length > 0) {
3815
+ if (this.to['multiple']) {
3816
+ this.formControl.setValue(res.data.map((c) => c[vf]));
3817
+ }
3818
+ else {
3819
+ const defaultValue = res.data[0];
3820
+ this.formControl.setValue(defaultValue?.[vf]);
3821
+ }
3822
+ }
3823
+ this.loading = false;
3824
+ // this.initOnlineSelection(); // Proceed with online selection after setting the value
3825
+ },
3826
+ error: (err) => {
3827
+ console.error("Failed to load default value from API:", err);
3828
+ this.loading = false;
3829
+ // this.initOnlineSelection(); // Fallback to local selection if API fails
3830
+ }
3831
+ });
3832
+ }
3833
+ // New method to handle loading the default value from the API
3834
+ onSelectionChange(val) {
3835
+ this.selectedItem = val;
3836
+ const vf = this.to['valueField'] || 'id';
3837
+ if (this.to['multiple']) {
3838
+ this.formControl.setValue(Array.isArray(val) ? val.map((c) => c[vf]) : []);
3839
+ }
3840
+ else {
3841
+ this.formControl.setValue(val?.[vf] ?? null);
3842
+ }
3843
+ }
3816
3844
  initOfflineSelection(withSetValue = true) {
3817
3845
  const val = this.formControl.value;
3818
3846
  const vf = this.to['valueField'] || 'id';
@@ -3843,7 +3871,12 @@ class GenericSelectorTypeComponent extends FieldType {
3843
3871
  const vf = this.to['valueField'] || 'id';
3844
3872
  if (val == null || (Array.isArray(val) && val.length === 0)) {
3845
3873
  this.selectedItem = this.to['multiple'] ? [] : null;
3846
- return;
3874
+ if (this.props['loadDefault'] == true) {
3875
+ this.loadDefaultValue();
3876
+ }
3877
+ else {
3878
+ return;
3879
+ }
3847
3880
  }
3848
3881
  if (this.to['multiple'] && Array.isArray(val) && val.length) {
3849
3882
  const calls = val.map((id) => this.api.get(id));