Question about "binding" simple html input to Y.Text shared text type

In order to “bind” to a Y.Text shared text type is the preferred way of changing the text inside the type to delete it out, then re-insert? Like the following?

  //called whenever a user types in the html input field
  inputTextChanged(inputText) {
    this.ytext_sharedText.delete(0, this.ytext_sharedText.toString().length);
    this.ytext_sharedText.insert(0, inputText);
  }

This seems to work fine, but I don’t know if this would be a bad practice? In the future I’ll be wanting to do this with multiple html form controls.

1 Like

This will not handle simultaneous editing from two users of the same text field. All you’re doing is overwriting the entire text. Proper use of Y.Text involves .insert(index, character) for each input.

I believe this is why there are no Y.Text bindings for and . The browser APIs simply don’t give this granular control of the text operations in this case. Proper handling of text is much easier if the entire text editor is programmatic.

Therefore, I would recommend that you use one of the editors that has Yjs bindings for your text fields.

1 Like

Thanks for your response @ViktorQvarfordt, that makes sense. Since I require standard html form input fields I’m thinking I’ll try and lock the input field for other users while one user is editing, then unlock the field when the editing user leaves the field.