Topic: MDB Bootstrap Support
Hello,
Maybe Im not getting it but select still showing "value" instead of text in the option text place when using controlled options (options as state object)
Mi object looks like this :
Select must render like this , right?
<select>
<option value="1"> Option one </option>....
but is rendering like this
<option value="1"> 1 </option>....
Jakub Mandra staff premium answered 6 years ago
Hi,
Have you updated mdbreact properly?
Material select actually should render like:
<ul class="select-dropdown ...">
<li {some attributes}>
<span data-mulitple="false" class="filtrable">Option A</span>
And values of options are in the inner state of the select component.
It's because it is not possible to attach those complicated material styles to native select component.
Here is the full code snippet:
import React, { Component } from "react";
import { MDBSelect } from "mdbreact";
class SelectPage extends Component {
state = {
options: [
{
checked: true,
disabled: false,
icon: null,
value: "A",
text: "Option A"
},
{
checked: false,
disabled: false,
icon: null,
text: "Option two",
value: "2"
},
{
checked: false,
disabled: false,
icon: null,
text: "Option three",
value: "3"
},
{
checked: false,
disabled: false,
icon: null,
text: "Option four",
value: "4"
}
]
};
displayValue = (val) => {
console.log(val);
}
render() {
return (
<div>
<MDBSelect
color="primary"
options={this.state.options}
selected="Choose your option"
search
searchLabel="Test"
getValue={this.displayValue}
/>
<label>Example label</label>
</div>
);
}
}
export default SelectPage;
gllermaly answered 6 years ago
Hi, did npm update mdbreact and version shows 4.8.7. Not sure if I need aditional steps
Thanks
gllermaly answered 6 years ago
Restarted project, replaced code with yours and did npm install and now texts are showing, but I have this warning:
Warning: Failed prop type: Invalid prop `data[0]` of type `object` supplied to `t`, expected `string`.
and "search" is searching against values and not texts , please fix or tell me how to do it
Thanks
gllermaly commented 6 years ago
Warning dissapears when I remove the search prop
Jakub Mandra staff premium commented 6 years ago
Thanks for report.
This is an actual bug, because search data is wrongly attached. It works ok, but we have to deal with that error. Will inform about the work progress.
Best
gllermaly commented 6 years ago
Thanks, I hope you are aware about "search" is searching against values and not texts , please fix or tell me how to do it
Jakub Mandra staff premium commented 6 years ago
Thank you, we are.
The fixes should be released in Monday, two weeks from now.
gllermaly commented 6 years ago
Nice! , please dont forget about this!!
Jakub Mandra staff premium commented 6 years ago
Issue has been resolved and is waiting on dev branch for release. It will take place on Monday :)
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- User: Free
- Premium support: No
- Technology: MDB React
- MDB Version: 4.8.4
- Device: PC
- Browser: Chrome
- OS: Ubuntu 16
- Provided sample code: No
- Provided link: No