-
Notifications
You must be signed in to change notification settings - Fork 0
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
Int value input not stripping all invalid characters on dialog submit #16
Comments
Replacing |
(Ignore the previous comment as using I have a solution although I haven't really understood what is going on behind the scenes, however it seems that My understanding therefore is as follows: This abstractControl can listen to, and will hear, changes to the value of the input box when a key is pressed. The NgControl injected in the e.g.
The comment in this thread and the answer to this stackoverflow led me to a possible solution, which would be to set the value of the abstractControl directly instead of using the NgControl's valueAccessor.
The value submitted for the inputs in the initial bug report will then be correct: |
In an edit dialog, the text input for an integer appears to work visually when entering non-numerical characters however on saving the value the last bad character entered is still there. And no error message is shown by the client or in the server logs.
For example, try to add a new item with a weight containing non-numerical characters, e.g.
Edit
name: "Bad Weight Input"
weight: "5kg"
The input textbox will, correctly, not show the non-numerical characters "kg":
![image](https://user-images.githubusercontent.com/11413124/184506593-70a18218-6024-41e2-9957-7eeb8ddb4090.png)
However, upon clicking save you will notice the item has not been created and in the console you can see the following value has actually been submitted to the server:
TO SUBMIT {name: 'BadWeight', weight: '5g'}
i.e. the last non-numerical character entered is still in the input value.
The
[dmIntInputDirective]
handleValue()
method appears to work as intended for the display in the text box.I have a doubt whether there needs to be a change detection forced before clicking "save" because after this line:
this.ngControl.valueAccessor.writeValue(cleanedValue);
(where cleanedValue is correctly e.g. "5")the value of
this.ngControl.value
is still e.g. "5g" inside the handleValue() function. So perhaps the ngControl value is not being written to before it is used by the "save" function..?Environment:
Seen on Chrome on Windows.
The text was updated successfully, but these errors were encountered: