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: MDBSelect Multiple doesn't return selection

marebear free asked 3 years ago


Excepted: Returns selected value/text for multiple select

Results: Doesn't return anything. Per the documentation, either option is not working.

<MDBSelect getSelectedValue={(e)=>console.log(e)} className="class" />

or

<MDBSelect getData={(e)=>console.log(e)} className="class" />

I have also looked at other support tickets. getValue method triggers an endless loop. My solution is working for non multiple select, but not for multiple....why? Any thoughts on this?

import React from "react";
import { MDBSelect } from "mdb-react-ui-kit";
import { useFormikContext } from "formik";

function AppMultiSelect({ label, name, error, options }) {
  const { touched, errors, setFieldValue } = useFormikContext();

  const handleSelection = (submission) => {
    console.log(name, ">>", submission);
      setFieldValue(name, submission);
  };

  return (
    <>
      <MDBSelect
        className="mb-3"
        data={options}
        label={label}
        name={name}
        getSelectedValue={(data) => {
          handleSelection(data);
        }}
        multiple
      />
      {errors[name] && touched[name] && (
        <p type="invalid" className="text-danger">
          {error}
        </p>
      )}
    </>
  );
}

export default AppMultiSelect;

My options follow this structure:

options: [
      { text: "Option 1", value: "opt1" },
      { text: "Option 2", value: "opt2" },
    ]

Wojciech Staniszewski staff commented 3 years ago

We have been planning to make some minor changes in MDBSelect for some time and first of all ease getting the selected value. Do you get any errors? Or the console just does not print anything?


marebear free commented 3 years ago

The console log doesn't print anything for getSelectedValue or getData for the multiple select.

getValue makes an endless loop.

Please note, that getSelectedValue works for the regular select. It is not working for the multiple select. Does that make sense?


Wojciech Staniszewski staff commented 3 years ago

Have you tried using getValue property?


marebear free commented 3 years ago

Thanks for responding!

Yes, per my pervious comment, getValue makes an endless loop.

My solution works for regular select, but not for the multiple select. I think there is something wrong with the multiple select...or if there is another property I'm not aware of. Do you have any other suggestions?


Wojciech Staniszewski staff commented 3 years ago

Sorry! I didn't notice. Unfortunately, the endless loop is a bug. We will try to fix it in this release (which is planned for October 18). Sorry for the inconvenience.



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB React
  • MDB Version: MDB5 1.3.0
  • Device: Mac
  • Browser: Chrome, Safari
  • OS: Big Sur 11.6
  • Provided sample code: Yes
  • Provided link: No