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

Allow empty input "defaults" or expose sanitize function #1435

Open
grichards23 opened this issue Oct 28, 2024 · 1 comment
Open

Allow empty input "defaults" or expose sanitize function #1435

grichards23 opened this issue Oct 28, 2024 · 1 comment

Comments

@grichards23
Copy link

grichards23 commented Oct 28, 2024

🚀 feature request

Description

Allow "defaulting" empty input values without having to write your own inputTransformFn.
For instance
[defaultInputValue]="0"
[defaultInputValue]="1"

Describe the solution you'd like

The issue we're running into is, some of our fields cannot be left empty/blank - such as a quantity field, can only be positive integers > 0.
Or price/cost fields can be any numeric value but cannot be undefined.

I wrote an output transform fn to catch that scenario and write 0 back to my model and it is working beautifully, however the field appears blank on blur.

I know I can write my own inputTransformFn but once I write my own, the directive's own mechanism for sanitizing is no longer leveraged (which works great btw) and I'm force to roll my own solution.

Ideally what I'd like is one of two things, an I apologize if I misunderstood something and this can easily be done today.

  1. Set a default "input" value so when empty it'll fall back to that value.
    or
  2. Use existing directive's string sanitization mechanism in my own custom written inputTransformFn that will scrub/remove non-numeric and special characters before my logic to check for empty/falsy and returning "1" or "0" depending on case.

Example

In this SB - if you provide a numeric value then blur - the appropriately formats the input string and updates the model as expected.
If you highlight the value in the field and remove it, and blur - 0 will get written to the model but the field remains empty. My hopes would be in this case that it would appear as "0.00"

https://stackblitz.com/edit/stackblitz-starters-byub7y?file=src%2Fapp%2Fapp.component.ts

@AdamSmid
Copy link

AdamSmid commented Nov 8, 2024

I would welcome this feature. In my case, I want the default value to be null for
<input name="limitValue" type="text" matInput mask="separator" [(ngModel)]="item.limit.value">
However, I currently have an empty string, but the backend only accepts numbers or null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants