Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number fields are defaulted to either min or max values from schema, even when optional #58

Closed
todda00 opened this issue Jun 30, 2016 · 8 comments
Assignees
Labels
Type: Bug Bug reports and their fixes

Comments

@todda00
Copy link
Contributor

todda00 commented Jun 30, 2016

When using a schema definition with either min, max, or both, the field is defaulted to either the min (if min is present), max (if only max is present). This is true for schema definitions where optional : true as well. This situation occurs for both TextField and NumField.

I would expect to see a blank field instead of defaulting to either min or max, especially for an optional field.

Example code and output:

...
  'height.feet':{
    type: Number,
    optional: true,
    min: 4,
    max: 8
  },
  'height.inches':{
    type: Number,
    optional: true,
    max: 11
  },
...
            <div className='col-xs-12 col-md-4'>
              <TextField name='height.feet' placeholder='Feet' label='Height - Feet' />
            </div>
            <div className='col-xs-12 col-md-4'>
              <TextField name='height.inches' placeholder='Inches' label="Height - Inches" />
            </div>

Result:
localhost_3005_register_player_athletics

@radekmie radekmie added the Type: Feature New features and feature requests label Jun 30, 2016
@radekmie radekmie self-assigned this Jun 30, 2016
@radekmie radekmie added the Type: Bug Bug reports and their fixes label Jun 30, 2016
@radekmie
Copy link
Contributor

It shouldn't happen with optional fields - that's a bug.


Yes, current implementation of SimpleSchemaBridge#getInitialValue gets into account min and max. If you think that's not a good idea, please leave a comment here.

@radekmie radekmie removed the Type: Feature New features and feature requests label Jun 30, 2016
@todda00
Copy link
Contributor Author

todda00 commented Jun 30, 2016

Behavior definitely needs to be changed for optional fields, but I also think its strange to set an initial value even when required. In my opinion you want to force the user to input a value, not default to either the max or min.

If someone wants a default, they can set the model.

@radekmie
Copy link
Contributor

Yep, I've fixed behaviour of optional fields, but I'm still thinking about those max and min... You have a point there - everybody can provide a default value in the model, but is that "any initial value possible" rule bad? It's hard to decide (at least for me), if a blank input is better than min or max (but the min seems to be more reasonable than the max).

@serkandurusoy
Copy link
Contributor

This has not been fixed for me with rc.23

@radekmie
Copy link
Contributor

radekmie commented Jul 7, 2016

You mean max and min, @serkandurusoy? If so, yes - it's not implemented, because I don't know if this would be a good change (as I said one comment above). If you meant optional fields, then, well - it should.

@radekmie radekmie reopened this Jul 7, 2016
@serkandurusoy
Copy link
Contributor

serkandurusoy commented Jul 7, 2016

Yes, I have an optional: true field with a max value (no default, no min) and it shows the max as an initial value when form is rendered.

budget: {
  type: Number,
  max: 2147483647,
  optional: true,
}

Regarding providing default values whether or not the field is optional, html does not have that behaviour, other form frameworks don't have it, it is certainly unexpected for me to find out that the form framework is providing default values for me when I don't explicitly tell it to.

I would want to user to think first before entering a value there. When there is an initial value provided automatically, it kind of leads the user to ignore that field because human perception kind of works like that. An input is something you put things in, and if there already is something in there, you automatically think you are done with it and don't even check if you wanted to enter the correct number in there.

So a default should not be provided in any case. Just bad UX!

@todda00
Copy link
Contributor Author

todda00 commented Jul 7, 2016

I just tried this with a field with optional: true in the schema and it is still populating with an initial value. Here are the props for an example field:

localhost_3005_register_player_athletics

and the corresponding schema:

  'height.feet':{
    type: Number,
    optional: true,
    min: 4,
    max: 8
  },

@todda00
Copy link
Contributor Author

todda00 commented Jul 7, 2016

And FWIW I agree that adding a initial value based off min / max is odd behavior. Like I said previously, if the developer wishes to set a default, they can do so with the model.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug reports and their fixes
Projects
Archived in project
Development

No branches or pull requests

3 participants