I have a mat-dialog that opens from an edit button in a (mat-)table.
When the dialog opens it gets passed data to populate some input fields.
One of those inputs has validation with the rule that it cannot be empty.
My problem is that the input element that receives an auto-populated value is not recognized by Angular as having a value at all (it has a 'value' in the web-inspector and on the screen).
This means that until the user edits the field either by deleting and reentering a character or typing something new, the 'save' button remains greyed-out. Not al fields need to be edited, if they receive a value it is a valid one.
So how can I get the validation to recognize that the input field is not empty but also that it does have a value? (The reason I can't just remove the validation, it has to have a value, ie != '').
So unless the user input is empty to start with or the user deletes the input, the validation should pass. Or to say it another way, if the input receives a value when the dialog opens, and the user leaves it well alone, the validation should pass.
A side effect of the auto-populated values not being recognized is that if a number is unchanged then it gets posted as null to the backend. So when the data is refreshed in the view, a number that was 30 and not edited by the user is now 0. This, because the form is displaying the auto-populated data, but somehow angular isn't "seeing" it.
simple input:
<div class="form">
<mat-form-field>
<input matInput #input
class="form-control"
placeholder="Name"
[(ngModel)]="data.name"
name="name"
selected="data.name"
required
[value]="this.getFunc?.name"
>
<mat-error *ngIf="data.name == ''">{{getErrorMessage()}}</mat-error>
</mat-form-field>
</div>
Not sure what to show from the component.ts files here(?!)
Using dialogRef.componentInstance = foo.bar; in the parent component, the dialog gets it's correct values in the input fields and IF the user deletes and then retypes a value, the correct value is sent back via the API.
The issue is that angular can't 'see' the input.
Tried a lot of different stuff, including every other answer on SO/here.
Sorry long text and little code, but there isn't anything to show how angular doesn't recognize that the input field holds a value.