mdb-select setting value programmatically


Topic: mdb-select setting value programmatically

starrcompanies asked 6 years ago

I want to be able to set my the mdb-select dropdown value in code from a model. I am using Reactive Forms. 

It doesn't appear to be working when I dynamically set the formControl value after init. I don't have the model before the formGroup, so I can initialize the formGroup/formControls before the page is loaded.  Is there a programmatic way to set the value of a dropdown?

Please advise!


Arkadiusz Idzikowski staff answered 5 years ago

We are already aware of the problem with passing objects as values. We also need to add a method that will allow to compare such values. I can't provide an ETA for that yet, but these changes should be added in one of the upcoming releases.


Arkadiusz Idzikowski staff answered 6 years ago

Hello,

How do you try to change this value? There is a setValue method in Reactive Forms, please try something like this:

this.yourFormGroupName.controls.yourControlName.setValue(value);

Regards,

Arek


ahuckenbeck answered 5 years ago

It's not working in my case. Mabye it's because i use an Object instead of String as value for select component. I don't understand why you do this restriction to string type value in IOption Interface?


octavian pro answered 5 years ago

Any new on this topic? If not using reactive forms, how to set a value programmatically?


Arkadiusz Idzikowski staff commented 5 years ago

What is the exact problem and which version of MDB Angular do you use?


cooper_lyt pro premium answered a year ago

Angular 16, It's not work!

      <mdb-form-control>
        <mdb-select id="project-input" mdbValidate formControlName="projectId" required>
          <mdb-option *ngFor="let option of projects" [value]="option.projectId">
            {{option.projectName}}
          </mdb-option>
        </mdb-select>
        <label mdbLabel for="project-input" class="form-label">Project</label>
      </mdb-form-control>

this.projectForm.get('projectId')!.setValue('1078140298338306');


Arkadiusz Idzikowski staff commented a year ago

I tested that using MDB Angular 5 version 5.0.0 and Angular 16 and could not find any problems. Could you please edit your post and provide an example of complete HTML and TS code on which we will be able to reproduce this problem?


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: 6.2.3
  • Device: desktop
  • Browser: Chrome
  • OS: windows 10
  • Provided sample code: No
  • Provided link: No