question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dinamicaly change the status of checked

See original GitHub issue

Hi,

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:open
  • Created 6 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

1reaction
lolobossecommented, May 9, 2017

Btw, quickfix for now:

Replace the original dependency in your package.json by:

"react-native-check-box": "git://github.com/crazycodeboy/react-native-check-box.git#dbd40836b09f7bc0316d13e30abdb66a799c5077"
0reactions
DavitVoskcommented, Jun 21, 2018
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found