SAP / fundamental-ngx

Fundamental Library for Angular is SAP Design System Angular component library
https://sap.github.io/fundamental-ngx
Apache License 2.0
269 stars 130 forks source link

Combobox with displayFn does not pre populate value #2968

Closed vinitkumar33 closed 3 years ago

vinitkumar33 commented 4 years ago

Is this a bug, enhancement, or feature request?

Bug

Briefly describe your proposal.

Can not pre populate value of combo box when its values are model with multiple attribute and has a displayFn.

Which versions of Angular and Fundamental Library for Angular are affected? (If this is a feature request, use current version.)

Fundamental-ngx 0.18.0

When a combo-box is used with display function where the dropdownValues is an object with multiple attribute. When we try to pre populate the combobox with default value, it doesnt work. It works perfectly fine for combobox without displayFn.

In the below example, I have tried to achieve populating combobox value on click of a button. I have two combo-box - One (disabledComboControl) properly populates values but the other one doesnt (disabledComboControl1). I have tried populating the value in multiple ways.. //this.customForm.controls.disabledComboControl1.patchValue('Newval'); or //this.customForm.controls.disabledComboControl1.patchValue({name1: 'AppleNew'}); Or //this.customForm.setValue({disabledComboControl: '1', disabledComboControl1: '2', disabledComboControl2: '3'});

None of the above works

HTML


<form [formGroup]="customForm">
    <fieldset fd-fieldset class="flex-form">
        <div fd-form-item>
          <label fd-form-label for="form-combo-2">Select Fruit11:</label>
            <input type='text' formControlName="disabledComboControl2"/>
            <label fd-form-label for="form-combo-2">Select Fruit:</label>
            <fd-combobox formControlName="disabledComboControl" fd-form-control id="form-combo-2"></fd-combobox>
            <fd-combobox [id]="ey"
                         formControlName="disabledComboControl1"
                         [dropdownValues]="dropdownValues"
                         [displayFn]="displayFnt">
            </fd-combobox>
        </div>
         <button fd-button
                        class="searchPageButton text-color" (click)="btnClicked()"
                        i18n="Clear|Clear@@SEARCH_VIEW_COMPONENT.Clear">click</button>
    </fieldset>
</form>

#### 
**Ts file**
import { Component } from '@angular/core';
import { FormGroup, FormControl, Validators } from '@angular/forms';

@Component({
    selector: 'fd-combobox-disabled-example',
    styleUrls: ['combobox-disabled-example.component.scss'],
    templateUrl: './combobox-disabled-example.component.html'
})
export class ComboboxDisabledExampleComponent {
    dropdownValues = ['Apple', 'Pineapple', 'Banana', 'Kiwi', 'Strawberry'];
    dropdownValues1 = [{name1: 'Apple1'}, {name1: 'Pineapple1'}, {name1: 'Banana'}, {name1: 'Kiwi'}, {name1:'Strawberry'}];
searchTerm: string;
    customForm = new FormGroup({
        disabledComboControl: new FormControl({ value: 'Kiwi12', disabled: true }, Validators.required),
        disabledComboControl1: new FormControl({value: null, disabled: false }, Validators.required),
        disabledComboControl2: new FormControl({ value: 'Ki21', disabled: false }, Validators.required)

    });

    btnClicked() {
         this.customForm.setValue({disabledComboControl: '1', disabledComboControl1: '2', 
         disabledComboControl2: '3'});

      //this.customForm.controls.disabledComboControl.patchValue('AppleNew');
      //this.customForm.controls.disabledComboControl1.patchValue();
      //this.customForm.controls.disabledComboControl2.patchValue('new1');

    }

    displayFnt(value) {
      return value.name1;
    }
}

#### Please provide relevant source code if applicable.
Provided above

#### Is there anything else we should know?
mikerodonnell89 commented 3 years ago

@vinitkumar33 So, a few problems with the source you've provided:

Closing this issue, because with the changes I suggested above, everything works fine but feel free to reopen for further discussion if necessary