Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislearn committed Aug 30, 2017
1 parent bc604f9 commit fe292e0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/widgets/input/NumberInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NumberInput extends Component {
}

render() {
const { label, fetchValue, step, style, disabled } = this.props;
const { label, fetchValue, step, style, disabled, min, max } = this.props;
return (
<TextField
disabled={disabled}
Expand All @@ -44,6 +44,8 @@ class NumberInput extends Component {
onChange={this.handleChange}
step={step}
type="number"
min={min}
max={max}
floatingLabelText={label}
/>
);
Expand Down
3 changes: 1 addition & 2 deletions src/widgets/input/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ class TextInput extends Component {
}

@observable _errorText;
@observable _value = ''
render() {
const { fetchValue, label, style, type, disabled } = this.props
return <TextField
label={label}
style={style}
type={type}
disabled={disabled}
value={this._value}
value={fetchValue(this)}
onChange={this.handleChange.bind(this)}
floatingLabelText={<span>{label}</span>}

Expand Down
8 changes: 4 additions & 4 deletions src/widgets/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ export function fetchValue(element, defaultValue = "") {
if (element.props.convert) {
if (element.props.convert.fetch) {
value = element.props.convert.fetch.apply(element, values)
} else {
} else if (typeof element.props.convert === 'function'){
value = element.props.convert.apply(element, values)
}else{
value = values.length == 1 ? values[0] : values.join(', ')
}
}else if (values.length == 1){
value = values[0]
}else{
value = values.join(', ')
value = values.length == 1 ? values[0] : values.join(', ')
}
return value
}
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function validateInput(target, key, descriptor) {
const method = descriptor.initializer;
descriptor.initializer = function () {
return function (event) {
if(this.props.validators){
if(this.props && this.props.validators){
this.props.validators.map((validator, index) => {
check.apply(this, [validator, this.props.errorMessages[index], event.target.value]);
});
Expand All @@ -24,7 +24,7 @@ export function validateForm(Form) {
if (this.wci) {
let all_clear = true;
this.wci.map((child) => {
if (child.props.validators) {
if (child && child.props && child.props.validators) {
for (var i = 0, l = child.props.validators.length; i < l; i++) {
if (!check.apply(child, [child.props.validators[i], child.props.errorMessages[i], getValues(child.props.record, child.props.source)[0]])) {
all_clear = false;
Expand All @@ -35,7 +35,7 @@ export function validateForm(Form) {
});
if (all_clear) {
console.log('all clear');
this.props.onSubmit(data);
this.props && this.props.onSubmit && this.props.onSubmit(data);
}
}
}
Expand Down

0 comments on commit fe292e0

Please sign in to comment.