@@ -2,22 +2,28 @@ import * as React from "react";
22import { FieldValue } from "simplr-forms/contracts" ;
33import { DomFieldProps } from "../contracts/field" ;
44
5- import { BaseDomField , BaseDomFieldState } from "../abstractions/base-dom-field" ;
6- import { FieldOnChangeCallback } from "../contracts/field" ;
5+ import {
6+ BaseDomField ,
7+ BaseDomFieldState
8+ } from "../abstractions/base-dom-field" ;
9+ import {
10+ FieldOnChangeCallback ,
11+ FieldOnChangeInternalCallback
12+ } from "../contracts/field" ;
13+ import {
14+ FormProps
15+ } from "../contracts/form" ;
16+
17+ export type TextOnChangeCallback = FieldOnChangeCallback < HTMLInputElement > ;
718
819/**
920 * Override the differences between extended interfaces.
10- *
11- * @export
12- * @interface Props
13- * @extends {CoreContracts.FieldProps }
14- * @extends {React.HTMLProps<HTMLInputElement> }
1521 */
1622export interface TextProps extends DomFieldProps , React . HTMLProps < HTMLInputElement > {
1723 name : string ;
1824 onFocus ?: React . EventHandler < React . FocusEvent < HTMLInputElement > > ;
1925 onBlur ?: React . EventHandler < React . FocusEvent < HTMLInputElement > > ;
20- onChange ?: FieldOnChangeCallback < HTMLInputElement > ;
26+ onChange ?: TextOnChangeCallback & FieldOnChangeInternalCallback ;
2127 ref ?: any ;
2228
2329 defaultValue ?: FieldValue ;
@@ -30,15 +36,25 @@ export class Text extends BaseDomField<TextProps, BaseDomFieldState> {
3036 }
3137
3238 protected OnChangeHandler : React . FormEventHandler < HTMLInputElement > = ( event ) => {
33- this . OnValueChange ( this . GetValueFromEvent ( event ) ) ;
39+ event . persist ( ) ;
3440
35- const newValue = this . FormStore . GetField ( this . FieldId ) . Value ;
41+ let newValue : string | undefined ;
42+ if ( ! this . IsControlled ) {
43+ this . OnValueChange ( this . GetValueFromEvent ( event ) ) ;
44+ newValue = this . FormStore . GetField ( this . FieldId ) . Value ;
45+ } else {
46+ newValue = this . GetValueFromEvent ( event ) ;
47+ }
3648
3749 if ( this . props . onChange != null ) {
3850 this . props . onChange ( event , newValue , this . FieldId , this . FormId ) ;
3951 }
4052
41- // 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+ }
4258 }
4359
4460 protected get RawDefaultValue ( ) {
0 commit comments