Topic: MDB React prefill select

bioaster pro asked 5 years ago


Hi, I managed to dynamically add selectOption to the DOM but I don't see how this can be prechecked. Any idea? Thanks

Jakub Mandra staff answered 5 years ago


<Select getValue={this.getValueOfSelect} multiple>
  <SelectOptions>
    {
      this.state.options.map(option =>         
        <SelectOption key={option} selected>{option}</SelectOption>
      )
    }
  </SelectOptions>
</Select>

bioaster pro answered 5 years ago


<SelectOptions>
{users.map(u=><SelectOptionkey={u.id}selected>{u.username}</SelectOption>)}
</SelectOptions>
does not work...

Mikołaj Smoleński staff commented 5 years ago

We will take a look at this before the next release and we will propose a solution. Best regards

Mikołaj Smoleński staff answered 5 years ago


Hi, Adding props 'selected' should fix Your issue. However, while adding element dynamically the component probably will need to be re-rendered. It is an interesting case. Best regards

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: Pro
  • Premium support: No
  • Technology: MDB React
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags