foxhound87 / mobx-react-form

Reactive MobX Form State Management
https://foxhound87.github.io/mobx-react-form
MIT License
1.1k stars 129 forks source link

Form converts string to number unexpectedly #543

Closed DieuAnh closed 1 year ago

DieuAnh commented 4 years ago

There's a strange behavior of mobx form for converting a value from string to number. In the following example, if I have model.name equals to 911, when I get values from form, I have a number instead of a string regardless of all efforts to make it a string. I think this is a bug to fix.

    addGeneration(model) {
        return {
            name: model.name.toString(),
            placeholder: 'Create or choose car generation(s)',
            rules: 'required',
            disabled: false,
            }
        }
    }
    @action.bound
    setFieldGenerations(models) {
        models.forEach(model => {
            this.fields.get('generations').add(this.addGeneration(model));
        })
    }
    setup() {
        const fields = {
            generations: []
        }

        return ({ fields });
    }
    hooks() {
        return {
            onSuccess(form) {
                let values = form.values();
                this.callbackNext(values['generations']);
            },
    }
foxhound87 commented 1 year ago

I can't replicate this issue. There are not enough information in your code to undestand your issue. You also are assigning the model name to the field name not field value.