Topic: Name Attribute on MDBSelect
sedonawebservices pro asked 5 years ago
Where does the name attribute go, and how does one access values submitted with a form, using this component? I tried placing the name attribute everywhere, and I can't access it from a submitted form method.
<MDBSelect>
<MDBSelectInput />
<MDBSelectOptions>
<MDBSelectOption value="1" selected>Option 1</MDBSelectOption>
<MDBSelectOption value="2">Option 2</MDBSelectOption>
</MDBSelectOptions>
</MDBSelect>
Jakub Mandra staff answered 5 years ago
No need to do that.
Checkdocuementation/api section
Little snippet:
getValueOfSelect = value => {
console.log(value);
};
render() {
return (
<Select
getValue={this.getValueOfSelect}
getTextContent={this.getValueOfSelect}
>
<SelectInputselected="Choose your option"/>
<SelectOptions>
<SelectOptiondisabled>Choose your option</SelectOption>
<SelectOption>Option nr 1</SelectOption>
<SelectOption>Option nr 2</SelectOption>
<SelectOption>Option nr 3</SelectOption>
<SelectOption>Option nr 4</SelectOption>
<SelectOptionselected>Option nr 5</SelectOption>
</SelectOptions>
</Select>
);
}
sedonawebservices pro answered 5 years ago
Ok. So I did this:
<MDBSelect id="valueType">
and
const valueType = document.querySelector('#valueType input').value
Jakub Mandra staff answered 5 years ago
Hi,
Select is not working as a native HTML select, because it wasn't possible to style it the material way :)
You have to retrieve selected data using getValue method (or getTextContent if you prefer) and then send it via Ajax.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Pro
- Premium support: No
- Technology: MDB React
- MDB Version: 4.7.1
- Device: Desktop
- Browser: Chrome
- OS: OS X
- Provided sample code: Yes
- Provided link: No