Dogfalo / materialize

Materialize, a CSS Framework based on Material Design
https://materializecss.com
MIT License
38.86k stars 4.74k forks source link

How to get the value from the select drop down #5996

Open basanthalluri opened 6 years ago

basanthalluri commented 6 years ago

I am trying to get the value from the select drop down through onChange action but the function not calling in react.

Here is my sample code for select drop down

{this.state.registerFormError.countryCode}

Here is my react code

handleInputChange (event) { alert("testing") // event.persist(); this.setState((state) => { state.registerForm[event.target.name] = event.target.value }); }

componentWillMount(){ console.log("executed") $(document).ready(function () { $('.dropdown-button').dropdown({ constrainWidth: false, hover: true, belowOrigin: true, alignment: 'left' }); $('select').material_select(); $('.dropdown-button').dropdown({ constrainWidth: false, hover: true, belowOrigin: true, alignment: 'left' }); $('.button-collapse').sideNav();

}); }

Gladear commented 6 years ago

React doesn't work well when used with other libraries. jQuery and Materialize are no exception. Now, you have two options if you don't want to struggle more and more for every component you'll do :

I know this probably isn't the answer you expected, but I still hope it will help you !

And for next posts, after pasting your code, select it and click the Insert code icon so it is more readable for everyone !

aarmel-sw commented 6 years ago

one example: $(this.refs.your_select).material_select(this._handleChange.bind(this))