Skip to content

Commit

Permalink
feat(rawValue): adding raw text in onChangeText
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-hur Santos Ott committed Apr 7, 2019
1 parent f0c7288 commit 754cddf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

## [1.12.0] - 2019-04-07

### Added

- Adding `rawText` in `onChangeText`. (Thanks to [questionablequestion](https://github.com/questionablequestion))

### Fixed

- Fixing return type of `getRawValue` in `ts definition`. (Thanks to [gabelerner](https://github.com/gabelerner))
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
copy-to-test:
rm -rf ../rn-test/react-native-masked-text
npm run clean
npm run build
cp -R dist ../rn-test/react-native-masked-text
copy-to-samples:
rm -rf /Users/ben/Documents/dev/react-native-masked-text-samples/ReactNativeMaskedTextSamples/lib
mkdir /Users/ben/Documents/dev/react-native-masked-text-samples/ReactNativeMaskedTextSamples/lib
cp -R lib /Users/ben/Documents/dev/react-native-masked-text-samples/ReactNativeMaskedTextSamples
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -592,9 +592,26 @@ const unmasked = this.zipCodeField.getRawValue()
// unmasked: 98765321
```

### ... Utils

#### Including the `rawText` in `onChangeText` [1.12.0+]

If you need the raw value in every text change, you can use the `includeRawValueInChangeText`.

It will provide the masked and the raw text in every text change.

```jsx
<TextInputMask
type={'cpf'}
value={this.state.value}
includeRawValueInChangeText={true}
onChangeText={(maskedText, rawText) => {
// maskedText: 123.456.789-01
// rawText: 12345678901
}}
/>
```

### ... Utils

#### Getting the `TextInput` instance
If you want to get the `TextInput` raw component, use the `getElement()` method:
Expand Down
2 changes: 1 addition & 1 deletion dist/lib/base-text-component.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/base-text-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@ export default class BaseTextComponent extends Component {

return new Promise((resolve, reject) => {
let maskedText = self._getMaskedValue(text);
const rawText = self.props.includeRawValueInChangeText ? self.getRawValueFor(maskedText) : undefined

if(self._mustUpdateValue(maskedText)) {
self.setState({
value: maskedText,
rawValue: self.props.includeRawValueInChangeText ? self.getRawValueFor(maskedText) : undefined
rawValue: rawText
}, () => {
resolve({
maskedText,
rawText: self.state.rawValue
rawText
});
});
} else {
Expand Down

1 comment on commit 754cddf

@diegormb06
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the documentation was wrong, it would have to include this feature

Please sign in to comment.