Skip to content

Commit

Permalink
fga-eps-mds#166 - MINOR: Removed workarround for generic input
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusoliveira30 committed Apr 12, 2018
1 parent 7237ab6 commit 24849b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions src/components/GenericField.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import PropTypes from 'prop-types';
import { Text, View, TextInput } from 'react-native';
import styles from '../Styles';


export default class GenericField extends Component {
constructor(props) {
super(props);
Expand All @@ -19,34 +18,36 @@ export default class GenericField extends Component {
text: newText.trim(),
},
// Callback from setState
() => { this.verificaTexto(this.state.text, this.props.validorRegex); },
() => { this.validateText(this.state.text, this.props.validorRegex); },
);
}

verificaTexto(text, regexTest) {
const isValid = regexTest.test(text);
validateText(text, regexTest) {
if (regexTest.global) {
console.warn('validateText()', 'Regexp using global flag! The results may be wrong.');
} else {
// Do nothing
}

// This is a needed workarround to make sure that 'isValid' has its true value
// DO NOT ERASE IF YOU DON'T KNOW A BETTER SOLUTION
console.debug(regexTest.test(text));
const isValid = regexTest.test(text);

if (isValid) {
console.warn('Valido');
this.setState({ validateMessage: 1 });
this.setState({ validateMessage: true });
} else {
console.warn('Invalido');
this.setState({ validateMessage: 0 });
this.setState({ validateMessage: false });
}
}

render() {
// Provavelmente mudar isso para um Style diferente. User uma linha vermelha, nao sei.
// Não usar uma msg.
let p;
if (this.state.validateMessage === 0) {
p = <Text>{this.props.errorMessage}</Text>;
} else {
if (this.state.validateMessage || this.state.validateMessage === -1) {
p = <Text />;
} else {
p = <Text>{this.props.errorMessage}</Text>;
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/screens/RegisterScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default class RegisterScreen extends React.Component {
`State of register page: ${JSON.stringify(this.state, null, 2)}`);

// Testing regex list
const sixMoreWordCharRegex = /\w{6,}/g;
const sixMoreWordCharRegex = /\w{6,}/;

return (
<View style={styles.principal}>
Expand Down

0 comments on commit 24849b0

Please sign in to comment.