Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: mdb-select setting value programmatically

starrcompanies free 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!


cooper_lyt premium answered 1 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 1 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?


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?


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.


ahuckenbeck free 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?


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



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

  • ForumUser: 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
Tags