Skip to content

Commit fdbbf06

Browse files
Text onChange from FormProps. (#59)
* Controlled mechanism implemented and onChange types for Field and Form updated. * Text onChange from FormProps. * Event persist added to Text.OnChangeHandler.
1 parent 953b665 commit fdbbf06

File tree

1 file changed

+10
-1
lines changed
  • packages/simplr-forms-dom/src/components

1 file changed

+10
-1
lines changed

packages/simplr-forms-dom/src/components/text.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import {
1010
FieldOnChangeCallback,
1111
FieldOnChangeInternalCallback
1212
} from "../contracts/field";
13+
import {
14+
FormProps
15+
} from "../contracts/form";
1316

1417
export type TextOnChangeCallback = FieldOnChangeCallback<HTMLInputElement>;
1518

@@ -33,6 +36,8 @@ export class Text extends BaseDomField<TextProps, BaseDomFieldState> {
3336
}
3437

3538
protected OnChangeHandler: React.FormEventHandler<HTMLInputElement> = (event) => {
39+
event.persist();
40+
3641
let newValue: string | undefined;
3742
if (!this.IsControlled) {
3843
this.OnValueChange(this.GetValueFromEvent(event));
@@ -45,7 +50,11 @@ export class Text extends BaseDomField<TextProps, BaseDomFieldState> {
4550
this.props.onChange(event, newValue, this.FieldId, this.FormId);
4651
}
4752

48-
// TODO: FormProps.OnFieldChange
53+
const formStoreState = this.FormStore.GetState();
54+
const formProps = formStoreState.Form.Props as FormProps;
55+
if (formProps.onChange != null) {
56+
formProps.onChange(event, newValue, this.FieldId, this.FormId);
57+
}
4958
}
5059

5160
protected get RawDefaultValue() {

0 commit comments

Comments
 (0)