Dropdown select default value not set

UI Components for React
Post Reply
KamalSalah
Posts: 1
Joined: 27 Sep 2022, 07:09

27 Sep 2022, 07:45

Hi, I just moved my code from Material UI to PrimeReact.
I loved PrimeReact but when I migrated to PrimeReact the only issue I got is the following:


ISSUE
When setting a default value, the value doesn't set
This code below is in Material UI code to set a default value but can not migrate this function for PrimereReact (dropdown) component.

Where do we add this code:
- The problem is we have to set its state when a row is rendered
- The problem occurs if we set the state in our row function

Can this be fixed, I am surprised that no one has reported this. Or have I missed it?
I am trying to explain as much detail as possible. Maybe I have missed anything but can not figure it out.
Infor me if you need more details of the code or information I am glad to provide them.

This code below is in Material UI code

THIS ROW
defaultValue={row?.userLevel}

Code: Select all

<div className="col-12 sm:col-12 md:col-6 lg:col-3">
            <FormControl fullWidth="true">
              <InputLabel id="userlevel">User Level</InputLabel>
              <Select
                labelId="userlevel"
                label="User Level"
                defaultValue={row?.userLevel}
                onChange={(e) =>
                  setData({ ...data, userLevel: e.target.value })
                }
              >
                <MenuItem value={5}>Super User</MenuItem>
                <MenuItem value={1}>Regular User</MenuItem>
              </Select>
            </FormControl>
          </div>

Melloware
Posts: 3716
Joined: 22 Apr 2013, 15:48

27 Sep 2022, 13:42

You don't need `defaultValue` just set the `value=` to a `useState` variable that is already filled out with your pre-selected value.
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 7 guests