Skip to content

Commit 7aaacb8

Browse files
committed
New methods, fixed some bugs
Version 1.0.7 focus methos, clear method, onRef prop,. Update README.md
1 parent e187041 commit 7aaacb8

File tree

5 files changed

+100
-18
lines changed

5 files changed

+100
-18
lines changed

Example/App.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import React, {Component} from "react";
2-
import {StyleSheet, Text, ScrollView} from 'react-native';
2+
import {StyleSheet, Text, ScrollView, TouchableOpacity} from 'react-native';
33
import TextInput from "react-native-input-validator";
44

55
export default class App extends Component {
66

77
constructor(props){
88
super(props);
9+
10+
this.input = [];
11+
912
this.state = {
1013
value: "Example of string",
1114
valueRequired: "",
@@ -14,36 +17,58 @@ export default class App extends Component {
1417
}
1518

1619
render(){
20+
this.input = [];
1721
return (
1822
<ScrollView style={styles.container}>
1923
<Text style={styles.title}>Example{"\n"}react-native-input-validator</Text>
2024
<TextInput
25+
onRef={(r) => {
26+
this.input.push(r);
27+
}}
2128
value={this.state.value}
2229
style={styles.input}
2330
onChangeText={(text) => {this.setState({value: text})}}>
2431
<Text>Default</Text>
2532
</TextInput>
2633
<TextInput
34+
onRef={(r) => {
35+
this.input.push(r);
36+
}}
2737
value={this.state.valueRequired}
2838
required={true}
2939
style={styles.input}
3040
onChangeText={(text) => {this.setState({valueRequired: text})}}>
3141
<Text>Required</Text>
3242
</TextInput>
3343
<TextInput
44+
onRef={(r) => {
45+
this.input.push(r);
46+
}}
3447
value={this.state.value}
3548
style={styles.input}
3649
type={"email"}
3750
onChangeText={(text) => {this.setState({value: text})}}>
3851
<Text>Email</Text>
3952
</TextInput>
4053
<TextInput
54+
onRef={(r) => {
55+
this.input.push(r);
56+
}}
4157
value={this.state.valueNumber}
4258
style={styles.input}
4359
type={"numeric"}
4460
onChangeText={(text) => {this.setState({valueNumber: text})}}>
4561
<Text>Number</Text>
4662
</TextInput>
63+
<TouchableOpacity
64+
style={styles.button}
65+
onPress={() => {
66+
this.input.map((item) => {
67+
console.log(item);
68+
});
69+
}}>
70+
<Text>Validate</Text>
71+
</TouchableOpacity>
4772
</ScrollView>
4873
);
4974
}
@@ -64,5 +89,11 @@ const styles = StyleSheet.create({
6489
flex: 1,
6590
width: "auto",
6691
minWidth: 150,
92+
},
93+
button: {
94+
marginTop: 20,
95+
alignItems: "center",
96+
padding: 20,
97+
backgroundColor: "#DDD"
6798
}
6899
});

Example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"react": "16.8.3",
1313
"react-dom": "^16.8.6",
1414
"react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
15-
"react-native-input-validator": "^1.0.3",
15+
"react-native-input-validator": "^1.0.7",
1616
"react-native-web": "^0.11.4",
1717
"validator": "^11.1.0"
1818
},

README.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,13 @@ import TextInput from 'react-native-input-validator';
5151

5252
#### Placeholder floating label
5353
```javascript
54-
// Require
54+
// Import
5555
import TextInput from 'react-native-input-validator';
56-
56+
```
57+
```javascript
5758
// Example
5859
<InputValidator
59-
ref={(r) => {
60+
onRef={(r) => {
6061
this.input = r;
6162
}}
6263
type="email"
@@ -67,30 +68,33 @@ import TextInput from 'react-native-input-validator';
6768
<Text>Default</Text>
6869

6970
</InputValidator>
70-
71+
```
72+
```javascript
7173
// Check Validation
72-
this.input.isValidated(); // Faster
73-
this.input.isValid();
74+
this.input.isValidated(); // Faster: Check validation state
75+
this.input.isValid(); // Alternative safer: Validate and check validation state
7476
```
7577

7678
#### Only text input
7779
```javascript
78-
// Require
80+
// Import
7981
import TextInput from 'react-native-input-validator';
80-
82+
```
83+
```javascript
8184
// Example
8285
<InputText
83-
ref={(r) => {
86+
onRef={(r) => {
8487
this.input = r;
8588
}}
8689
type="email"
8790
value={this.state.value}
8891
style={styles.input}
8992
onChangeText={(text) => {this.setState({value: text})}} />
90-
93+
```
94+
```javascript
9195
// Check Validation
92-
this.input.isValidated(); // Faster
93-
this.input.isValid();
96+
this.input.isValidated(); // Faster: Check validation state
97+
this.input.isValid(); // Alternative safer: Validate and check validation state
9498
```
9599

96100
## ⚡️ Run example
@@ -124,15 +128,29 @@ Open Expo Client on your device. Use it to scan the QR code printed by `expo sta
124128

125129
### Handlers
126130

127-
Same of `TextInput`.
131+
Same of `TextInput` like `onChangeText` etc...
132+
Read more here: https://facebook.github.io/react-native/docs/textinput.html
133+
134+
Additional Handlers | Description | Type | Default | Note
135+
------------------|-------------|------|---------|-------
136+
onRef | Reference of the TextInput instance | Function | | Important for validate fields |
137+
138+
### Methods
139+
140+
Same of `TextInput` like `focus()`, `clear()`, `blur()` etc...
128141
Read more here: https://facebook.github.io/react-native/docs/textinput.html
129142

143+
Additional Methods | Description | Type | Default | Note
144+
------------------|-------------|------|---------|-------
145+
isValidated | Check if state of TextInput is valid | Bool
146+
isValid | Validate the TextInput and return the validation state | Bool
147+
130148
### Props
131149

132-
Same of `TextInput`.
150+
Same of `TextInput` like `editable`, `autoFocus` etc...
133151
Read more here: https://facebook.github.io/react-native/docs/textinput.html
134152

135-
Property | Description | Type | Default | Note
153+
Additional Property | Description | Type | Default | Note
136154
------------------|-------------|------|---------|-------
137155
type | Type of input | String | `dafault` | |
138156
symbol | Symbol for `currency` type | String | | |

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-input-validator",
3-
"version": "1.0.3",
3+
"version": "1.0.7",
44
"description": "React native input with floating label and data validation",
55
"main": "index.js",
66
"scripts": {

src/InputValidator.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,21 @@ class InputValidator extends Component {
4545
* Component did mount
4646
*/
4747
componentDidMount() {
48+
if(typeof this.props.onRef === 'function') {
49+
this.props.onRef(this);
50+
}
4851
this.validate();
4952
}
5053

54+
/**
55+
* Component did unmount
56+
*/
57+
componentDidUnmount() {
58+
if(typeof this.props.onRef === 'function') {
59+
this.props.onRef(undefined);
60+
}
61+
}
62+
5163
/**
5264
* Get locale
5365
* @returns {string}
@@ -225,6 +237,27 @@ class InputValidator extends Component {
225237
Keyboard.dismiss();
226238
}
227239

240+
/**
241+
* Focus
242+
*/
243+
focus() {
244+
this.input.focus();
245+
}
246+
247+
/**
248+
* Update
249+
*/
250+
update() {
251+
this.input.update();
252+
}
253+
254+
/**
255+
* Clear
256+
*/
257+
clear() {
258+
this.input.clear();
259+
}
260+
228261
/**
229262
* On Focus
230263
* @param event

0 commit comments

Comments
 (0)