Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component data validation check #602

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions haxe/ui/components/NumberStepper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ private class ValueHelper {
stepper.removeClass("invalid-value");
}

@:privateAccess(haxe.ui.core.InteractiveComponent)
stepper._isComponentDataValid = valid;

return parsedValue;
}

Expand Down
23 changes: 23 additions & 0 deletions haxe/ui/containers/properties/Property.hx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +23,7 @@ class Property extends HBox implements IDataComponent {
@:clonable @:behaviour(DefaultBehaviour) public var min:Null<Float>;
@:clonable @:behaviour(DefaultBehaviour) public var max:Null<Float>;
@:clonable @:behaviour(DefaultBehaviour) public var precision:Null<Int>;
@:behaviour(DataValidBehaviour) public var isComponentDataValid:Bool;
}

//***********************************************************************************************************
Expand Down Expand Up @@ -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
//***********************************************************************************************************
Expand Down
9 changes: 9 additions & 0 deletions haxe/ui/core/InteractiveComponent.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions haxe/ui/validators/Validator.hx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package haxe.ui.validators;

import haxe.ui.core.InteractiveComponent;
import haxe.ui.core.Component;

class Validator implements IValidator {
Expand Down Expand Up @@ -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<Bool> {
Expand Down