node.js - ReactJS event does not fire when Semantic-UI css is loaded -


i began learning reactjs , tried implement simple multiple choice question. works fine if leave styles out, if include semantic-ui's css file, things stop working properly. specifically, onchange handler in multiplechoiceanswer never called, other lifecycle functions still work properly. code below.

question.js

var react = require('react');  var multiplechoiceanswer = react.createclass({   getinitialstate: function () {     return {ischecked: false};   },   componentdidmount: function () {     console.log('answer mounted');   },   handlechange: function (event) {     console.log('state changed');     this.setstate({ischecked: event.target.checked});   },   render: function () {     var self = this;     return (       react.createelement('div', {classname: 'field'},         react.createelement('div', {classname: 'ui radio checkbox'},           react.createelement('input', {type:'radio', name:'answer_', defaultvalue:self.props.data.text, defaultchecked: self.state.ischecked, onchange:self.handlechange}),           react.createelement('label', null, self.props.data.text)))     );   } });  var multiplechoicequestion = react.createclass({   handlechange: function (event, selected) {     console.log('stuff changed');   },   getinitialstate: function() {     return {};   },   componentdidmount: function () {     console.log('question mounted');   },   handleclick: function(event) {     console.log('click!');     this.setstate({});   },   render: function () {     var rows = this.props.data.map(function (item) {       return (         react.createelement(multiplechoiceanswer, {key:item.id, data:item})       );     });     return (       react.createelement('div', {classname: 'ui form', onsubmit: this._onsubmit},         react.createelement('h3', null, 'what correct answer?'),         react.createelement('div', {classname: 'grouped fields'}, rows),         react.createelement('input', {type:'button', value:'submit now', onclick:this._onsubmit}))     )   },    _onsubmit: function() {     console.log('submitted');   } });  module.exports.multiplechoicequestion = multiplechoicequestion ; 

index.ejs

<!doctype html> <html>   <head>     <title>react isomorphic server side rendering example</title>     <!-- <link href='/semantic.min.css' rel="stylesheet" type="text/css">-->   </head>   <body>     <h1 id="main-title">react isomorphic server side rendering example</h1>     <div id="react-main-mount">       <%- reactoutput %>     </div>       <!-- comment out main.js see server side rendering -->     <script src="/jquery-2.1.3.min.js"></script>     <script src="/semantic.min.js"></script>   <script>   $(document).ready(function () {     $('.ui.checkbox').checkbox();   });   </script>     <script src="/main.js"></script>   </body> </html> 

can please help? it's stupid can't simple radio button work >.>

i got work. removed change handler question component instead of answer component , gave each input in answer component defaultchecked , defaultvalue propery. 2 properties key things made work.

var react = require('react');  var multiplechoiceanswer = react.createclass({   getinitialstate: function () {     return {ischecked: false};   },   componentdidmount: function () {     console.log('answer mounted');   },   render: function () {     return (       react.createelement('div', {classname: 'field'},         react.createelement('div', {classname: 'ui radio checkbox'},           react.createelement('input', {type:'radio', name:'answer', id:'answer_' + this.props.id, defaultchecked:false, defaultvalue:this.props.data.text}),           react.createelement('label', {htmlfor:'answer_' + this.props.id}, this.props.data.text)))     );   } });  var multiplechoice = react.createclass({   handlechange: function (event, selected) {     console.log('selected value: ', event.target.value);   },   getinitialstate: function() {     return {};   },   componentdidmount: function () {     console.log('question mounted');   },   render: function () {     var rows = this.props.data.answers.map(function (item) {       return (         react.createelement(multiplechoiceanswer, {key:item.id, data:item, id:item.id})       );     });      return (       react.createelement('div', {classname: 'ui form', onsubmit: this._onsubmit},         react.createelement('div', {classname: 'grouped fields', onchange:this.handlechange},         react.createelement('label', null, 'what correct answer?'),         rows),         react.createelement('input', {type:'button', value:'submit now', onclick:this._onsubmit}))     )   },    _onsubmit: function() {     console.log('submitted');   } });  module.exports.multiplechoice = multiplechoice; 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -