1+ import { useCallback } from 'react' ;
12import {
23 type ArrayError ,
34 useFormObject ,
45 getErrorObject ,
56 type SetValueArg ,
67} from '@togglecorp/toggle-form' ;
78import { DeleteBinTwoLineIcon } from '@ifrc-go/icons' ;
8- import { randomString } from '@togglecorp/fujs' ;
9+ import { isNotDefined , randomString } from '@togglecorp/fujs' ;
910
1011import Button from '#components/Button' ;
1112import NonFieldError from '#components/NonFieldError' ;
@@ -51,6 +52,31 @@ function SourceInformationInput(props: Props) {
5152 ? getErrorObject ( errorFromProps ?. [ value . client_id ] )
5253 : undefined ;
5354
55+ const handleSourceFieldChange = useCallback (
56+ ( newValue : string | undefined ) => {
57+ if (
58+ isNotDefined ( newValue )
59+ || newValue . startsWith ( 'http://' )
60+ || newValue . startsWith ( 'https://' )
61+ || newValue === 'h'
62+ || newValue === 'ht'
63+ || newValue === 'htt'
64+ || newValue === 'http'
65+ || newValue === 'http:'
66+ || newValue === 'http:/'
67+ || newValue === 'https'
68+ || newValue === 'https:'
69+ || newValue === 'https:/'
70+ ) {
71+ onFieldChange ( newValue , 'source_link' ) ;
72+ return ;
73+ }
74+
75+ onFieldChange ( `https://${ newValue } ` , 'source_link' ) ;
76+ } ,
77+ [ onFieldChange ] ,
78+ ) ;
79+
5480 return (
5581 < div className = { styles . sourceInformationInput } >
5682 < NonFieldError error = { error } />
@@ -69,7 +95,7 @@ function SourceInformationInput(props: Props) {
6995 name = "source_link"
7096 value = { value . source_link }
7197 error = { error ?. source_link }
72- onChange = { onFieldChange }
98+ onChange = { handleSourceFieldChange }
7399 disabled = { disabled }
74100 />
75101 < Button
0 commit comments