How to get text input from the user in our plugin on a text field and put them over the artboard ?
I used inner html text field to get the input.
If my text box id is #txt_bx and the Function that I use for Text is
function createText(text, { color = "white" } = {}) {
const { selection} = require("scenegraph");
const { Text, Color } = require("scenegraph");
const newText = new Text();
newText.text = text;
newText.fill = new Color(color);
selection.insertionParent.addChild(newText);
newText.placeInParentCoordinates({x: 0, y: 0}, selection.insertionParent.localCenterPoint);
return newText;
}
The code you show here works as expected. As long as text is definded and non-empty, a white point text node gets created.
Either, just overlooked the text node (it is white on a presumably white artboard, after all), or some other part of your code (not shown here) is where it breaks.
All in all, that’s all the help I can give you without further inormation. How (or where) do you call createText()?
Best,
Pablo
PS: If I could ask for a favor: Please, in the future, use titles that say what your question is about. I assume you want help, so Help me out with this! is redundant (or at least belongs into your text). Here, a suitable title might have been “How to insert text” or something like this. This allows others (and you and me, when we want to reference the topic) to search for it, reduce effort for moderating the forums etc. Also, I’m much more willing to help when I can quickly see what the topic is (generally) about without having to read all the text at first. Then, I can quickly decide if I’m able to help. Thank you very much in advance
Assuming your using a <input /> element, its value is accessible via .value, not .innerHTML. Try using something like this and see if it works for you:
const text = document.querySelector('#txt_bx').value;
createText(text);
Calls your function createText with the wrong arguments. It will call it and pass the click event as the first parameter, meaning text will not be a string, but an event. This will allow you to access the input element, e.g., using evt.target and its value with evt.target.value. The easiest option, here, would probably be to replace the above code with
Sorry, my bad. I somehow though about an event on a button (which doesn’t have a value). evt.target here is your button element, meaning instead of evt.target.value, you’ll have to determine the value of your <input /> here, using something like document.querySelector('txt-bx').value.
The function is fine. I ran it and, as stated above, it does what it’s supposed to do (or at least the code works as expected, if creating white text is your goal )