MDBSelect Problem


Topic: MDBSelect Problem

Nitin.Chanana asked 6 years ago

How can we set value as an id of an element and text as displayed as options and get id from getValue method? My code is written below.. Thanks

per:[{checked: true,
        disabled: false,
            icon: null,
            text:"Per Team",
           value: "1"

        },
        {  
          checked: false,
          disabled: false,
              icon: null,
              text:"Per Player",
              value: "2"

        },
        {  
          checked: false,
          disabled: false,
              icon: null,
              text:"Per 2 Person Team",
             value: "3"
            }],

this.handleChange("PerTeam",value)} options={this.state.per} selected="Select Fee Per"/>


Anna Morawska staff answered 6 years ago

Hi there,

please try the code shown bellow:

import React, { Component } from "react";
import { MDBSelect } from "mdbreact";

class TextareaPage extends Component {
      state={
          per: [{
              checked: true,
              disabled: false,
              icon: null,
              text: "Per Team",
              value: "1"
            },
            {
              checked: false,
              disabled: false,
              icon: null,
              text: "Per Player",
              value: "2"
            },
            {
              checked: false,
              disabled: false,
              icon: null,
              text: "Per 2 Person Team",
              value: "3",
              id: "id"
            }],
      }

      handleChange = (value) => {
           console.log(value)
       }

  render() {
        return (
              <>
        <MDBSelect getValue={(value) => this.handleChange(value)} options={this.state.per}             selected="Select Fee Per"/>
              </>
        );
      }
    }

export default TextareaPage;

Nitin.Chanana commented 6 years ago

Thanks Anna, I upgrade my project to 4.9.0 and now its working.


Anna Morawska staff commented 6 years ago

Ok, awesome, always happy to help :)


Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Resolved

Specification of the issue
  • User: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: 4.8.4
  • Device: Lenovo Desktop
  • Browser: Google Chrome
  • OS: Windows 10
  • Provided sample code: No
  • Provided link: No