dinamicaly change the status of checked
See original GitHub issueHi,
I’m trying to dinamically change the status of the checkBox, because I want to have one checkBox that we can call “Check All”, and as the name says, it will change all the status of the children checkbox to true or false, depending on what this one is set. I made the code but, when I change the state of the checked object, the screen is not updating the children Checkbox to what was suppose to be(I can confirm that the status was changing using the logs). It this not yet implemented, or is it a bug or I’m doing something wrong? (I’m using version 1.0.4) Code:
export default class MainScreen extends React.Component {
constructor(props) {
super(props);
this.ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1.id !== r2.id});
this.state = {
list: [],
dataSource: this.ds.cloneWithRows([]),
check: {},
checkAll: false,
};
}
static navigationOptions = {
title: 'Main',
headerVisible: false
};
_checkAll = () => {
const { checkAll, list, check } = this.state;
const callback = () => {
console.log("checkAll", checkAll);
list.map(student => {
check[student.name].checked = !check[student.name].checked;
console.log("check: " + student.name, check[student.name].checked);
this.setState({check});
});
}
this.setState({checkAll: !this.state.checkAll}, callback);
}
_checkStudent = (student) => {
console.log("checking student", student);
const { check } = this.state;
console.log("checking check", check);
check[student.name].checked = !check[student.name].checked;
this.setState({check});
}
render() {
// const { navigate } = this.props.navigation;
const { check, checkAll, dataSource } = this.state;
return (
<Image source={require('./../images/background_no_logo.png')} style={styles.container}>
<CheckBox
style={{padding: 10}}
onClick={()=>this._checkAll()}
isChecked={this.state.checkAll}
rightText={this.text.checkText}
/>
<ListView
style={styles.listView}
dataSource={this.state.dataSource}
enableEmptySections={true}
renderRow={(student) =>
<View style={styles.row}>
<CheckBox
style={{paddingLeft: 10, paddingRight:10}}
onClick={() => this._checkStudent(this.state.check[student.name])}
isChecked={this.state.check[student.name].checked}
/>
<Text style={{color:'#336463', fontSize:20, flex: 1}}>
{`${student.name}`}
</Text>
</View>
}
/>
</Image>
)
}
}
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8
Top Results From Across the Web
Update status of dynamically created checkboxes in jquery by ...
I am getting back an array of checkbox values from a separate function. These values need to be passed to a separate function...
Read more >Dynamically changing the value of a checkbox depending on ...
Am working on a checkbox input and am when it is clicked to opens some input fields in the DOM, when not clicked...
Read more >dynamic check box's checked change event. - MSDN - Microsoft
User-677917721 posted. Hi I am biginer in ASP.net I want to write some code on the checkbox chechedChange event using the C#. and...
Read more >Dynamically set the checkbox to be checked or unchecked
I want to dynamically set the checkbox to be checked or unchecked;. I tried document.getElementById('checkbox').checked = true , but it ...
Read more >Provide notification of dynamic changes to content
Where dynamic content is updated either automatically or in response to a user action, make sure that users are notified of this update...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Btw, quickfix for now:
Replace the original dependency in your
package.json
by:Guys you can use https://github.com/DavitVosk/react-native-check-box.git fork