admin管理员组文章数量:1414870
This is my code :
onChangeTextPrice(value) {
const newPrice = parseInt(value, 10).toLocaleString(['ban', 'id']);
return this.setState({ price: formatted });
}
If I console.log(newPrice)
, it will give me the format, for example : 10.000.000
but for some reason react native textinput doesn't use this value instead it show 10000000
.
but if I change TextInput
value like this:
<TextInput
keyboardType="numeric"
value={'10.000.000'}
multiline={false}
underlineColorAndroid="transparent"
onChange={val => this.onChangeTextPrice(val)}
It works. Why is that ?
This is my code :
onChangeTextPrice(value) {
const newPrice = parseInt(value, 10).toLocaleString(['ban', 'id']);
return this.setState({ price: formatted });
}
If I console.log(newPrice)
, it will give me the format, for example : 10.000.000
but for some reason react native textinput doesn't use this value instead it show 10000000
.
but if I change TextInput
value like this:
<TextInput
keyboardType="numeric"
value={'10.000.000'}
multiline={false}
underlineColorAndroid="transparent"
onChange={val => this.onChangeTextPrice(val)}
It works. Why is that ?
Share Improve this question edited Jul 10, 2018 at 6:16 Ankit Agarwal 30.8k5 gold badges40 silver badges63 bronze badges asked Jul 10, 2018 at 6:10 william anputrawilliam anputra 1691 gold badge5 silver badges12 bronze badges 8- I have never used react but reading this document seems giving the answer as this is masking and masking needs to be declared before initialization. github./benhurott/react-native-masked-text – Ullas Hunka Commented Jul 10, 2018 at 6:25
-
I guess
keyboadType="numeric"
will result in aninput type="number"
which does only alow numbers without formating – Lars-Olof Kreim Commented Jul 10, 2018 at 6:41 - Can you try this ponent npmjs./package/react-currency-input – Pramod Commented Jul 10, 2018 at 6:52
- I use github./react-native-munity/react-native-text-input-mask for the input masking. – Shivam Commented Jul 10, 2018 at 9:35
- @Pramod it didn't work – william anputra Commented Jul 10, 2018 at 9:41
1 Answer
Reset to default 2You might wanna use one of the following packages in order to achieve simple/plex input maskings.
github./benhurott/react-native-masked-text
github./react-native-munity/react-native-text-input-mask
A nice tutorial can be found here
本文标签: javascriptHow do i update text input value to use currency formatStack Overflow
版权声明:本文标题:javascript - How do i update text input value to use currency format - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745225863a2648605.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论