'How to write directive to allow input field with type= text to allow 'words'?
enter image description here I am using ngxdatatable in reactive forms where user can update all the fields in the table. i have three fields/columns for e.g fields a,b and c and they are dynamic as created below:
-- code for ngxdatatable columns
<div [formgroup]= this.form[rowindex]
<ngx-datatable-column *ngFor="let column of columns; let i = index;" name="{{column.name}}" prop="{{column.prop}}">
<ng-template #buttonsTemplate let-row="row" let-value="value" ngx-datatable-cell-template>
<input type =text isReadonly ="isreadonly">
</ng-template>
</ngx-datatable-column></div>
I am facing challenge in defining my validation for field B/column B,
1. **field b** can be autocalculated as number from field a and field c , **b = a+c**, but
user can't enter number manually in field b , on manual input only few strings are allowed like 'test', 'ok', 'any'. how can I achieve this ?
2. I tried to implement it via custom validation which works fine during manual input but it is failing because field/col B is autocalculated it shows error for number which is a valid scenario , as validation is only to be shown when user tries to input manually.
> this.fb.builder{ field a = validtion.Required,
> validation.patter(_number) field c=validtion.Required,
> validation.patter(_number) field b = customValidator }
>
>
> export function customValidator(c:abstract control) :{key:value}{
> if(c.value=='test' || c.value==''any || c.value == 'ok'} return null
>
> else {allowed:false} }
3. I thought of trying to achieve it with keydown event using directive , but not sure how to write a directive which allows words 'any', 'ok', 'test' and not anything else.**please suggest how can i write the directive for this as I am new to angular.**
4. Please suggest if you think any better approach can be used.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
