Add a text inside multiline input, without reset initial content

May anyone helpe me on how to add a text inside a multiline input? I.e, when i click a button add a text inside a multiline input in current position in text. The way bubble works all the initial content of multiline is changed.

@gaurav @StevenM @emmanuel

1 Like

HI @juancosta900 sorry, I am not sure I understand the question?

Hi @StevenM. Just looking for a way to add a text inside existing multiline text. ALL Bubble’s funccionality is to add a new content , for example, change the input data, but i can’t find a way. Example of what i want:

Input A: Current Text Current Text Current Text…

Result When click a Button add New text

Input A: Current Text (New Text) Current Text Current Text…

The New Text must depend on the Text cursor position.

Have you tried auto-binding the thing?

There’s no such direct workflow.What you can do is

  1. Create a small group (say group ‘X’), set its type to text and hide it
  2. set the initial content of the multiline input to be the ‘group X’s text’
  3. now you can display whatever you want initially as also the group X’s text
  4. When button is clicked -> take the data from multiline input, modify it as u need -> display the result in group X -> reset multiline input

Thanks, but It seems doesn’t work.
What i need is to add a preset text inside the multiline input text like the gif below

Do you need the text to be formatted like in your gif?
If yes i don’t think you can do that because the multiline input in Bubble is an html textarea and you can’t style individual text in a textarea.

If you don’t need to style the added text then i might have some idea.
Will try it and get back to you if it works.

Thanks friend. The style is not important. I wait Your solution

Ok so here is the idea.
You’re going to use copy and paste actions to achieve this.
For the copying, you can use, the Air Copy to Clipboard plugin.
Unfortunately the plugin currently doesn’t support paste from clipboard so i was hoping i could update the plugin with a paste action but it seems it’s not that simple.

But the idea was that when the user clicks on the text to be inserted, you will copy that text, then give focus to the input and do a paste action to paste the text in the current cursor position.

The challenge will be how to implement the paste action. It seems due to browser security it may not be easy to pull it off

Thanks. But I was using Copy to ClipBoard but it was not practit for my users and still has some bugs. I used the mention workflow with @, but It does not work in Rich Text input.

Thanks @gaurav . But I was using Copy to ClipBoard but it was not practit for my users and still has some bugs. I used the mention workflow with @, but It does not work in Rich Text input. Stilo waiting any solution.

Any Idea. @NigelG @vincent56 @fayewatson

I can’t think of any Bubble native way of doing it, so will need a bit of HTML/JS ?

Its a simple functionality that Bubble should add and have. @emmanuel

1 Like

I suspect it is easy enough with a little Javascript.



function insertAtCaret(areaId, text) {
		var txtarea = document.getElementById(areaId);
		if (!txtarea) { return; }

		var scrollPos = txtarea.scrollTop;
		var strPos = 0;
		var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ?
			"ff" : (document.selection ? "ie" : false ) );
		if (br == "ie") {
			var range = document.selection.createRange();
			range.moveStart ('character', -txtarea.value.length);
			strPos = range.text.length;
		} else if (br == "ff") {
			strPos = txtarea.selectionStart;

		var front = (txtarea.value).substring(0, strPos);
		var back = (txtarea.value).substring(strPos, txtarea.value.length);
		txtarea.value = front + text + back;
		strPos = strPos + text.length;
		if (br == "ie") {
			var ieRange = document.selection.createRange();
			ieRange.moveStart ('character', -txtarea.value.length);
			ieRange.moveStart ('character', strPos);
			ieRange.moveEnd ('character', 0);;
		} else if (br == "ff") {
			txtarea.selectionStart = strPos;
			txtarea.selectionEnd = strPos;

		txtarea.scrollTop = scrollPos;

insertAtCaret('myField', "foo");

The following code works in Bubble:
Just add this code inside HTML Script:

insertAtCaret: function(myValue){
return this.each(function(i) {
if (document.selection) {
//For browsers like Internet Explorer
sel = document.selection.createRange();
sel.text = myValue;
else if (this.selectionStart || this.selectionStart == ‘0’) {
//For browsers like Firefox and Webkit based
var startPos = this.selectionStart;
var endPos = this.selectionEnd;
var scrollTop = this.scrollTop;
this.value = this.value.substring(0, startPos)+myValue+this.value.substring(endPos,this.value.length);
this.selectionStart = startPos + myValue.length;
this.selectionEnd = startPos + myValue.length;
this.scrollTop = scrollTop;
} else {
this.value += myValue;
$(‘#test’).click(function() {

And than add a button id called “test” and a text input id called “textarea”

This is how works in bubble:


Looks good :slight_smile:

Do you mind if I add this to BuildingOnBubble ?

OK, @NigelG.
I add this in ShowCase. See there.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.