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

fix(material/datepicker): add ability to have numeric zero value in input #24813

Merged
merged 2 commits into from
May 5, 2022
Merged

fix(material/datepicker): add ability to have numeric zero value in input #24813

merged 2 commits into from
May 5, 2022

Conversation

diprokon
Copy link
Contributor

fix(material/datepicker): add ability to have numeric zero value in input

Shows valid formatted value for 'falsy' values (exp 0)
Custom DateAdapter (exp TimestampDateAdapter) can have valid numeric 0 value (for timestamp it is 1/1/1970), but datepicker input doesn't show formatted value

@google-cla
Copy link

google-cla bot commented Apr 21, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@zarend
Copy link
Contributor

zarend commented Apr 21, 2022

Hello @diprokon , this seems reasonable, but you could add a unit test please?

? this._dateAdapter.format(value, this._dateFormats.display.dateInput)
: '';
this._elementRef.nativeElement.value =
value != null ? this._dateAdapter.format(value, this._dateFormats.display.dateInput) : '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't think also try to format other falsy values like an empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it's already there. '!= null' checks only for 'null' and 'undefined'. 0, "", false, etc. will be formatted

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @crisbeto is saying that maybe '' should be treated like null. I think it is technically correct to try to parse it though. We don't know what the generic type D will be, but it could be string. If its not string people shouldn't really be passing '' anyways. I think we can keep it like this and try to presubmit it in Google. If we find a lot of people using '' to mean null we may want to change it

…nput

Shows valid formatted value for 'falsy' values (exp 0)
Custom DateAdapter (exp TimestampDateAdapter) can have valid numeric 0 value (for timestamp it is 1/1/1970), but datepicker input doesn't show formatted value
@diprokon
Copy link
Contributor Author

@zarend can you check the tests, please?

@devversion devversion removed request for devversion and a team April 28, 2022 16:51
? this._dateAdapter.format(value, this._dateFormats.display.dateInput)
: '';
this._elementRef.nativeElement.value =
value != null ? this._dateAdapter.format(value, this._dateFormats.display.dateInput) : '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @crisbeto is saying that maybe '' should be treated like null. I think it is technically correct to try to parse it though. We don't know what the generic type D will be, but it could be string. If its not string people shouldn't really be passing '' anyways. I think we can keep it like this and try to presubmit it in Google. If we find a lot of people using '' to mean null we may want to change it

@mmalerba mmalerba added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels May 3, 2022
@mmalerba mmalerba merged commit 5f4d7e2 into angular:main May 5, 2022
mmalerba pushed a commit that referenced this pull request May 5, 2022
…nput (#24813)

* fix(material/datepicker): add ability to have numeric zero value in input

Shows valid formatted value for 'falsy' values (exp 0)
Custom DateAdapter (exp TimestampDateAdapter) can have valid numeric 0 value (for timestamp it is 1/1/1970), but datepicker input doesn't show formatted value

* fix(material/datepicker): add ability to have numeric zero value in input

Add tests

(cherry picked from commit 5f4d7e2)
mmalerba pushed a commit that referenced this pull request May 5, 2022
…nput (#24813)

* fix(material/datepicker): add ability to have numeric zero value in input

Shows valid formatted value for 'falsy' values (exp 0)
Custom DateAdapter (exp TimestampDateAdapter) can have valid numeric 0 value (for timestamp it is 1/1/1970), but datepicker input doesn't show formatted value

* fix(material/datepicker): add ability to have numeric zero value in input

Add tests

(cherry picked from commit 5f4d7e2)
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request May 13, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/cdk](https://github.com/angular/components) | dependencies | patch | [`13.3.6` -> `13.3.7`](https://renovatebot.com/diffs/npm/@angular%2fcdk/13.3.6/13.3.7) |
| [@angular/material](https://github.com/angular/components) | dependencies | patch | [`13.3.6` -> `13.3.7`](https://renovatebot.com/diffs/npm/@angular%2fmaterial/13.3.6/13.3.7) |

---

### Release Notes

<details>
<summary>angular/components</summary>

### [`v13.3.7`](https://github.com/angular/components/blob/HEAD/CHANGELOG.md#&#8203;1337-chiffon-carambola-2022-05-11)

[Compare Source](angular/components@13.3.6...13.3.7)

##### material

| Commit | Type | Description |
| -- | -- | -- |
| [0bede63d33](angular/components@0bede63) | fix | **datepicker:** add ability to have numeric zero value in input ([#&#8203;24813](angular/components#24813)) |
| [7a122f7f03](angular/components@7a122f7) | fix | **expansion:** inconsistent spacing for anchor buttons ([#&#8203;24882](angular/components#24882)) |
| [e486ed93e4](angular/components@e486ed9) | fix | **menu:** focus the first item when opening menu on iOS VoiceOver ([#&#8203;24733](angular/components#24733)) |

#### Special Thanks

Dmytro Prokhorov, Kristiyan Kostadinov and Zach Arend

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).

Co-authored-by: cabr2-bot <[email protected]>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1349
Reviewed-by: Epsilon_02 <[email protected]>
Co-authored-by: Calciumdibromid Bot <[email protected]>
Co-committed-by: Calciumdibromid Bot <[email protected]>
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants