@@ -23,6 +23,7 @@ import * as FormStoreActions from "../actions/form-store";
2323import { FSHContainer } from "../stores/form-stores-handler" ;
2424import { FieldValidationType } from "../contracts/validation" ;
2525import { FormStoreStateRecord } from "../contracts/form-store" ;
26+ import { ModifierValue } from "../contracts/value" ;
2627
2728export interface CoreFieldState {
2829 FormStoreState : FormStoreStateRecord ;
@@ -141,7 +142,7 @@ export abstract class CoreField<TProps extends CoreFieldProps, TState extends Co
141142 * Current or default field value.
142143 */
143144 protected get Value ( ) : FieldValue {
144- // If state is defined
145+ // If state is defined and Value is set
145146 if ( this . state != null && this . state . Value != null ) {
146147 // Return its value
147148 return this . state . Value ;
@@ -153,10 +154,23 @@ export abstract class CoreField<TProps extends CoreFieldProps, TState extends Co
153154
154155 protected abstract get ControlledValue ( ) : FieldValue ;
155156
156- protected ProcessValueBeforeStore ( value : FieldValue ) : FieldValue {
157+ protected ProcessValueBeforeStore ( value : FieldValue ) : ModifierValue {
157158 // Parse and normalize value
158159 if ( value != null ) {
159- return this . NormalizeValue ( this . ParseValue ( value ) ) ;
160+ const modifierValue : ModifierValue = {
161+ Value : value
162+ } ;
163+ const parsedValue = this . ParseValue ( modifierValue ) ;
164+
165+ const result : ModifierValue = {
166+ Value : this . NormalizeValue ( parsedValue . Value )
167+ } ;
168+
169+ if ( parsedValue . TransitionalValue != null ) {
170+ result . TransitionalValue = this . NormalizeValue ( parsedValue . TransitionalValue ) ;
171+ }
172+
173+ return result ;
160174 }
161175 return value ;
162176 }
@@ -165,7 +179,7 @@ export abstract class CoreField<TProps extends CoreFieldProps, TState extends Co
165179 return this . FormatValue ( value ) ;
166180 }
167181
168- protected ParseValue ( value : FieldValue ) : FieldValue {
182+ protected ParseValue ( value : ModifierValue ) : ModifierValue {
169183 if ( this . props . parseValue != null ) {
170184 const parser = this . props . parseValue as FieldParseValueCallback ;
171185 value = parser ( value ) ;
@@ -222,7 +236,8 @@ export abstract class CoreField<TProps extends CoreFieldProps, TState extends Co
222236 state . FormStoreState = newFormStoreState ;
223237 }
224238 const newFieldState = this . FormStore . GetField ( this . FieldId ) ;
225- state . Value = this . ProcessValueFromStore ( newFieldState . Value ) ;
239+ const value = newFieldState . TransitionalValue != null ? newFieldState . TransitionalValue : newFieldState . Value ;
240+ state . Value = this . ProcessValueFromStore ( value ) ;
226241 return state ;
227242 } ) ;
228243 }
@@ -282,19 +297,29 @@ export abstract class CoreField<TProps extends CoreFieldProps, TState extends Co
282297 * ========================
283298 */
284299
300+ private processedOrEmptyModifierValue ( value : FieldValue , processor : ( value : FieldValue ) => ModifierValue ) : ModifierValue {
301+ if ( value != null ) {
302+ return processor ( value ) ;
303+ }
304+ return {
305+ Value : value
306+ } ;
307+ }
308+
285309 /**
286310 * Registers a field in FormStore or throws if the field was already registered
287311 */
288312 private registerFieldInFormStore ( ) : void {
289- const defaultValue = this . ProcessValueBeforeStore ( this . RawDefaultValue ) ;
290- const initialValue = this . ProcessValueBeforeStore ( this . RawInitialValue ) ;
291- const value = this . ProcessValueBeforeStore ( this . RawValue ) ;
313+ const defaultValue = this . processedOrEmptyModifierValue ( this . RawDefaultValue , this . ProcessValueBeforeStore . bind ( this ) ) ;
314+ const initialValue = this . processedOrEmptyModifierValue ( this . RawInitialValue , this . ProcessValueBeforeStore . bind ( this ) ) ;
315+ const value = this . processedOrEmptyModifierValue ( this . RawValue , this . ProcessValueBeforeStore . bind ( this ) ) ;
292316 this . FormStore . RegisterField (
293317 this . FieldId ,
294318 this . props . name ,
295- defaultValue ,
296- initialValue ,
297- value ,
319+ defaultValue . Value ,
320+ initialValue . Value ,
321+ value . Value ,
322+ value . TransitionalValue ,
298323 this . props ,
299324 this . FieldsGroupId
300325 ) ;
0 commit comments