Skip to content

Checkbox - add validation state invoked by validate() #2672

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions demo/src/screens/componentScreens/CheckboxScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';
import {StyleSheet} from 'react-native';
import {Assets, Colors, View, Text, Checkbox} from 'react-native-ui-lib'; //eslint-disable-line
import {Assets, Colors, View, Text, Button, Checkbox, CheckboxRef} from 'react-native-ui-lib'; //eslint-disable-line

export default class CheckboxScreen extends Component {
state = {
Expand All @@ -10,7 +10,28 @@ export default class CheckboxScreen extends Component {
value4: true,
value5: false,
value6: false,
value7: true
value7: false,
validationText: '',
validationColor: Colors.$textDefault
};

checkbox = React.createRef<CheckboxRef>();

onPress = () => {
this.checkbox.current?.validate();
};

onValueChange = (value: boolean) => {
this.setState({value7: value}, () => {
console.log('onValueChange: ', value);
});
};

onChangeValidity = (value?: boolean) => {
this.setState({
validationText: String(value),
validationColor: value === true ? Colors.$textSuccess : Colors.$textDangerLight
});
};

render() {
Expand Down Expand Up @@ -77,6 +98,24 @@ export default class CheckboxScreen extends Component {
iconColor={Colors.green10}
/>
</View>

<View marginT-20>
<Text text60 $textDefault marginB-10>
Validation
</Text>
<Text marginB-4 color={this.state.validationColor}>{this.state.validationText}</Text>
<View row centerV spread marginB-10>
<Checkbox
required
onChangeValidity={this.onChangeValidity}
ref={this.checkbox}
value={this.state.value7}
onValueChange={this.onValueChange}
label={'This is a checkbox'}
/>
<Button size={'small'} label={'Validate'} onPress={this.onPress}/>
</View>
</View>
</View>
);
}
Expand Down
Loading