Data, set via code is not submitting

I have a Text Input on my site, so I try to set its value using the following code:

$w('#input1').value = item._id;

This works perfectly, the Input displays the field I need, but I have a problem when I try to use it to submit the form. On the same page, I have a contact form that uses the value of my Text Input when i save it in another database. I use this code:

$w('#KWrite').setFieldValue('ref', $w('#input1').value);

The problem is that the value of the Text Input is not stored in the database. Database field is just empty.

This happens because I use the code to set the value of my Text Input, but it is not connected to the dataset directly.
Is this a bug?