When Focus done on input field, fields remove the data

I am trying to input data using this function. this function is fetching data and doing formfilling but when the form focus on the input field or I try to submit from all, data disappears from all the fields and all input fields become red.

 if (Data[key].formname) {   
          $("[formcontrolname='"+Data[key].formname+"']").focus(); 
          $("[formcontrolname='"+Data[key].formname+"']").val(Data[key].value);
                        
                        await wait (1000)                        
                    }