Skip to content

Commit 5cf8e15

Browse files
committed
2.13.0
* add unformatted value to onChange callback
1 parent 7ff3134 commit 5cf8e15

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ import 'react-phone-input-2/lib/style.css'
233233
</tr>
234234
</table>
235235

236+
onChange(value, country, e, formattedValue)
237+
236238
Country data object not returns from onKeyDown event
237239

238240
<table>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-phone-input-2",
3-
"version": "2.12.1",
3+
"version": "2.13.0",
44
"description": "A react component to format phone numbers",
55
"main": "lib/lib.js",
66
"typings": "index.d.ts",

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ class PhoneInput extends React.Component {
555555
this.numberInputRef.setSelectionRange(caretPosition, caretPosition);
556556
}
557557

558-
if (onChange) onChange(this.state.formattedNumber.replace(/[^0-9]+/g,''), this.getCountryData(), e);
558+
if (onChange) onChange(formattedNumber.replace(/[^0-9]+/g,''), this.getCountryData(), e, formattedNumber);
559559
});
560560
}
561561

@@ -585,7 +585,7 @@ class PhoneInput extends React.Component {
585585
formattedNumber
586586
}, () => {
587587
this.cursorToEnd();
588-
if (this.props.onChange) this.props.onChange(formattedNumber.replace(/[^0-9]+/g,''), this.getCountryData(), e);
588+
if (this.props.onChange) this.props.onChange(formattedNumber.replace(/[^0-9]+/g,''), this.getCountryData(), e, formattedValue);
589589
});
590590
}
591591

test/ReactPhoneInput.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('<PhoneInput /> event handlers', () => {
7373
/>)
7474

7575
fireEvent.change(phoneInput.querySelector('.form-control'), {target: {value: '12345'}})
76-
expect(mockFn).toHaveBeenCalledWith('12345', {name: 'United States', dialCode: '1', 'format': '+. (...) ...-....', countryCode: 'us'}, expect.any(Object))
76+
expect(mockFn).toHaveBeenCalledWith('12345', {name: 'United States', dialCode: '1', 'format': '+. (...) ...-....', countryCode: 'us'}, expect.any(Object), '+1 (234) 5')
7777
})
7878
})
7979

test/dev:js/demo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ class Demo extends React.Component {
184184
<p>State manipulations</p>
185185
<PhoneInput
186186
value={this.state.value}
187-
onChange={(value, country, e) => {console.log(value, country, e); this.setState({ value })}}
187+
onChange={(value, country, e, formattedValue) => {console.log(value, country, e, formattedValue);
188+
this.setState({ value })}}
188189
enableAreaCodes
189190
defaultErrorMessage='Invalid value'
190191
isValid={(value, country) => {

0 commit comments

Comments
 (0)