Skip to content

Commit

Permalink
fixed num values
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerwin Brunner committed Jul 4, 2019
1 parent 4c96d8f commit 9ad7e95
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions packages/uniforms-polaris/src/NumField.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React /*, {Component} */ from 'react';
import React, {Component} from 'react';
import {TextField} from '@shopify/polaris';

import connectField from 'uniforms/connectField';
import filterDOMProps from 'uniforms/filterDOMProps';

// const noneIfNaN = x => (isNaN(x) ? undefined : x);
const noneIfNaN = x => (isNaN(x) ? undefined : x);

const Num_ = ({
decimal,
Expand Down Expand Up @@ -37,34 +37,34 @@ const Num_ = ({
/>
);

// // NOTE: React < 16 workaround. Make it optional?
// class Num extends Component {
// constructor() {
// super(...arguments);
// NOTE: React < 16 workaround. Make it optional?
class Num extends Component {
constructor() {
super(...arguments);

// this.state = {value: '' + this.props.value};
this.state = {value: '' + this.props.value};

// this.onChange = this.onChange.bind(this);
// }
this.onChange = this.onChange.bind(this);
}

// componentWillReceiveProps({decimal, value}) {
// const parse = decimal ? parseFloat : parseInt;
componentWillReceiveProps({decimal, value}) {
const parse = decimal ? parseFloat : parseInt;

// if (noneIfNaN(parse(value)) !== noneIfNaN(parse(this.state.value.replace(/[.,]+$/, '')))) {
// this.setState({value: value === undefined || value === '' ? '' : '' + value});
// }
// }
if (noneIfNaN(parse(value)) !== noneIfNaN(parse(this.state.value.replace(/[.,]+$/, '')))) {
this.setState({value: value === undefined || value === '' ? '' : '' + value});
}
}

// onChange({target: {value}}) {
// const change = value.replace(/[^\d.,-]/g, '');
onChange(value) {
const change = value.replace(/[^\d.,-]/g, '');

// this.setState({value: change});
// this.props.onChange(noneIfNaN((this.props.decimal ? parseFloat : parseInt)(change)));
// }
this.setState({value: change});
this.props.onChange(noneIfNaN((this.props.decimal ? parseFloat : parseInt)(change)));
}

// render() {
// return Num_({...this.props, onChange: this.onChange, value: this.state.value});
// }
// }
render() {
return Num_({...this.props, onChange: this.onChange, value: this.state.value});
}
}

export default connectField(Num_);
export default connectField(Num);

0 comments on commit 9ad7e95

Please sign in to comment.