Skip to content

Commit

Permalink
Oops, string is no child of Object
Browse files Browse the repository at this point in the history
  • Loading branch information
moritztim committed Nov 16, 2023
1 parent ae9fd0b commit 5ff33e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
20 changes: 20 additions & 0 deletions addons/form/nodes/FormLabel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,26 @@ class_name FormLabel extends Label
## "The selected input is not an input according to Form.is_input() or null"
@export var nonstandard_input := false

## Validator
@export var validator: Validator:
set(new_val):
if validator != null && input != null:
push_error("Validator must be compatible with the type of subject")
return
if input.get_theme_stylebox("normal") == null:
validator.style_valid = input.get_theme_stylebox("normal")
validator = new_val

## Name of the property to validate
@export var subject: StringName:
set(new_val):
if input == null:
subject = new_val
elif has_property(input, new_val) && (validator == null || typeof(input[new_val]) == validator.get_type()):
subject = new_val
else:
push_error("Validator must be compatible with the type of subject")

## "Input value must not be empty"
@export var input_required := false:
set(new_val):
Expand Down
2 changes: 1 addition & 1 deletion addons/form/nodes/Validator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var valid := false
var broken_rules := {}

## Validates subject against all rules and returns validity
func validate(subject: Object) -> bool:
func validate(subject) -> bool:
if typeof(subject) != get_type():
push_error("Subject must be of type ", get_type(), " (see Variant.Type)")
broken_rules = {}
Expand Down
4 changes: 3 additions & 1 deletion addons/form/nodes/Validators/StringValidator.gd
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ func _on_text_changed(
## Validates given text against all rules and returns validity
func validate(
## Text to validate
subject: Object
subject
) -> bool:
if !(subject is String):
return
super.validate(subject)
var _regex := RegEx.new()

Expand Down

0 comments on commit 5ff33e2

Please # to comment.