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

Spinner does not set model to null when a min value is specified #3318

Closed
battmanz opened this issue Jul 5, 2017 · 5 comments
Closed

Spinner does not set model to null when a min value is specified #3318

battmanz opened this issue Jul 5, 2017 · 5 comments
Assignees
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Milestone

Comments

@battmanz
Copy link
Contributor

battmanz commented Jul 5, 2017

I'm submitting a ... (check one with "x")

[x] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if request is not on the roadmap already https://github.com/primefaces/primeng/wiki/Roadmap
[ ] support request => Please do not submit support request here, instead see http://forum.primefaces.org/viewforum.php?f=35

Plunkr Case (Bug Reports)
http://plnkr.co/edit/ZMwNY1AzjUzVKVuBt50o?p=preview

Current behavior
If the spinner has a min value specified, then the model cannot be set to null.

Expected behavior
Even with amin value, the model should be set to null if I clear out all the text.

Minimal reproduction of the problem with instructions

  1. Launch the Plunkr above.
  2. Notice that there are two spinners (the only difference is that the "bad" one has a min value set).
  3. Enter a value (e.g. 5) into both inputs.
  4. Press the "Show Me My Data" button just to prove that it's working.
  5. Delete all text from both inputs (you have to delete the text twice on the bottom one, because 0 automatically gets inserted).
  6. With NO text in either input, press the "Show Me My Data" button again.
  7. Notice that the "good number" is set to null (as I want), but notice that the "bad number" is still set to 0. I don't want it to be zero, I want it to be null.

What is the motivation / use case for changing the behavior?
I need a nullable number field with a min value. Zero is a valid value, so I need null to indicate that there is no value.

Please tell us about your environment:

  • Angular version: 4.2.3
  • PrimeNG version: 4.0.3
  • Browser: Chrome 59, Firefox 54

  • Language: TypeScript 2.3.4

  • Node (for AoT issues): node --version = 7.10.0

@battmanz
Copy link
Contributor Author

battmanz commented Jul 6, 2017

I can submit a pull request for this. Is the PrimeNG team willing to accept one?

@Mrtcndkn
Copy link
Contributor

Mrtcndkn commented Jul 7, 2017

Sure you can create a PR about this after the review we can merge it. @battmanz

@Mrtcndkn Mrtcndkn added Status: Pending Review Issue or pull request is being reviewed by Core Team Type: Bug Issue contains a bug related to a specific component. Something about the component is not working and removed Status: Pending Review Issue or pull request is being reviewed by Core Team labels Jul 7, 2017
@battmanz
Copy link
Contributor Author

battmanz commented Jul 7, 2017

@Mrtcndkn Thanks for getting back to me. The issue boils down to this block of code inside the parseValue method:

if(val.trim() === '') {
  value= this.min !== undefined ? this.min : null;
}

I personally find it surprising that if the min were 5, for example, then if the text box is empty, the underlying model would be set to 5. So I would like to change it to this:

if(val.trim() === '') {
  value= null;
}

However, that would be a breaking change. So do you think I should add a new flag as an attribute (e.g. [nullIfEmpty]="true")? Then the code would look like this:

if(val.trim() === '') {
  value= (!this.nullIfEmpty && this.min !== undefined) ? this.min : null;
}

Bottom line: Do I need a flag or not?

@cagataycivici
Copy link
Member

PR merged.

@benshabatnoam
Copy link

I'm using primeng v6.1.6 and it in not containing this merged code. As you can see in this image below, the js file doesn't have this change:

image

Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Issue contains a bug related to a specific component. Something about the component is not working
Projects
None yet
Development

No branches or pull requests

4 participants