Browse Source

set input value to initial value in extrinsics form when enabling optional

Mokhtar Naamani 5 years ago
parent
commit
1836dabdf4

+ 1 - 1
packages/react-params/src/Param/Amount.tsx

@@ -15,7 +15,7 @@ import Bare from './Bare';
 function onChange ({ onChange }: Props): (_: string) => void {
   return function (value: string): void {
     onChange && onChange({
-      isValid: true,
+      isValid: value ? true : false,
       value: new BN(value || 0)
     });
   };

+ 10 - 1
packages/react-params/src/Param/Option.tsx

@@ -12,6 +12,7 @@ import { Toggle } from '@polkadot/react-components';
 
 import translate from '../translate';
 import Param from './index';
+import getInitValue from '../initValue';
 
 interface Props extends CProps, I18nProps {}
 
@@ -25,6 +26,14 @@ function Option ({ className, defaultValue, isDisabled, name, onChange, onEnter,
     });
   }, [isActive]);
 
+  function doSetIsActive(active: boolean) {
+    active && onChange && onChange({
+      isValid: true,
+      value: getInitValue(sub as TypeDef)
+    })
+    setIsActive(active);
+  }
+
   return (
     <div className={className}>
       <Param
@@ -44,7 +53,7 @@ function Option ({ className, defaultValue, isDisabled, name, onChange, onEnter,
               ? t('include option')
               : t('exclude option')
           }
-          onChange={setIsActive}
+          onChange={doSetIsActive}
           value={isActive}
         />
       )}