diff --git a/haxe/ui/components/NumberStepper.hx b/haxe/ui/components/NumberStepper.hx index f892b5ec0..606ecf06d 100644 --- a/haxe/ui/components/NumberStepper.hx +++ b/haxe/ui/components/NumberStepper.hx @@ -495,6 +495,9 @@ private class ValueHelper { stepper.removeClass("invalid-value"); } + @:privateAccess(haxe.ui.core.InteractiveComponent) + stepper._isComponentDataValid = valid; + return parsedValue; } diff --git a/haxe/ui/containers/properties/Property.hx b/haxe/ui/containers/properties/Property.hx index c26b33fe9..49dec2ff7 100644 --- a/haxe/ui/containers/properties/Property.hx +++ b/haxe/ui/containers/properties/Property.hx @@ -1,11 +1,13 @@ package haxe.ui.containers.properties; +import haxe.ui.behaviours.Behaviour; import haxe.ui.behaviours.DataBehaviour; import haxe.ui.behaviours.DefaultBehaviour; import haxe.ui.components.Label; import haxe.ui.core.Component; import haxe.ui.core.CompositeBuilder; import haxe.ui.core.IDataComponent; +import haxe.ui.core.InteractiveComponent; import haxe.ui.core.IValueComponent; import haxe.ui.data.ArrayDataSource; import haxe.ui.data.DataSource; @@ -21,6 +23,7 @@ class Property extends HBox implements IDataComponent { @:clonable @:behaviour(DefaultBehaviour) public var min:Null; @:clonable @:behaviour(DefaultBehaviour) public var max:Null; @:clonable @:behaviour(DefaultBehaviour) public var precision:Null; + @:behaviour(DataValidBehaviour) public var isComponentDataValid:Bool; } //*********************************************************************************************************** @@ -115,6 +118,26 @@ private class PropertyValueBehaviour extends DataBehaviour { } } +@:dox(hide) @:noCompletion +@:access(haxe.ui.core.Component) +private class DataValidBehaviour extends Behaviour { + private var _property:Property; + + public function new(property:Property) { + super(property); + _property = property; + } + + public override function get():Variant { + var builder = cast(_property._compositeBuilder, PropertyBuilder); + if (builder.editor != null && (builder.editor is InteractiveComponent)) { + return cast(builder.editor, InteractiveComponent).isComponentDataValid; + } + + return true; + } +} + //*********************************************************************************************************** // Builder //*********************************************************************************************************** diff --git a/haxe/ui/core/InteractiveComponent.hx b/haxe/ui/core/InteractiveComponent.hx index 96d4e2f14..a2201a4cf 100644 --- a/haxe/ui/core/InteractiveComponent.hx +++ b/haxe/ui/core/InteractiveComponent.hx @@ -117,6 +117,15 @@ class InteractiveComponent extends Component implements IFocusable implements IV } return value; } + + private var _isComponentDataValid:Bool = true; + /** + If the current value of the component passed all validators (or, "should this value be used?") + **/ + public var isComponentDataValid(get, null):Bool; + private function get_isComponentDataValid():Bool { + return _isComponentDataValid; + } //*********************************************************************************************************** // Internal diff --git a/haxe/ui/validators/Validator.hx b/haxe/ui/validators/Validator.hx index c6c06ca82..90ed6a098 100644 --- a/haxe/ui/validators/Validator.hx +++ b/haxe/ui/validators/Validator.hx @@ -1,5 +1,6 @@ package haxe.ui.validators; +import haxe.ui.core.InteractiveComponent; import haxe.ui.core.Component; class Validator implements IValidator { @@ -65,12 +66,17 @@ class Validator implements IValidator { component.removeClasses([validStyleName, invalidStyleName], true, true); } + @:access(haxe.ui.core.InteractiveComponent) private function onValid(component:Component) { component.swapClass(validStyleName, invalidStyleName, true, true); + // @:privateAccess(haxe.ui.core.InteractiveComponent) + if (component is InteractiveComponent) cast(component, InteractiveComponent)._isComponentDataValid = true; } + @:access(haxe.ui.core.InteractiveComponent) private function onInvalid(component:Component) { component.swapClass(invalidStyleName, validStyleName, true, true); + if (component is InteractiveComponent) cast(component, InteractiveComponent)._isComponentDataValid = false; } private function validateString(s:String):Null {