Adding LineEdit Fields Dynamically

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By deepseaprincess

I’m trying to dynamically add LineEdit fields to my ui so that users can enter additional properties. This is what the scene looks like:

enter image description here

enter image description here

Here is the code attached to the “Add Property” button:

func _pressed():
	var labelProp = Label.new()
	labelProp.text = "Property"
	add_child(labelProp)
	var lineProp = LineEdit.new()
	add_child(lineProp)
	labelProp = Label.new()
	labelProp.text = "Property Value"
	add_child(labelProp)
	lineProp = LineEdit.new()
	add_child(lineProp)

When I click the Add Property button this is what happens:
enter image description here

What can I do to get the LineEdit fields properly added?

:bust_in_silhouette: Reply From: Ghostrix98

I believe you need to call add_child on $VBoxContainer. Like so get_parent().add_child(node) because the script is attached to the button.

That was it thank you so much!

deepseaprincess | 2021-10-12 15:45