hurt-tomatoH
Refine3y ago
2 replies
hurt-tomato

remove spaces before submit

Hi everyone !!
I try to modify a phone number to remove space before i send to the API. I get from a mui phone input. I have a state in which i store the phone number. When i submit i have a value like this +33 6 10 20 30 40. I have made a function to remove the spaces like following :
 const removeSpaces = (phrase: string) => {
        return phrase.replace(/\s/g, "");
 };

which i call in the on finish like this :
const handleSubmitUsersEdit = (values: FieldValues) => {
        values.mobile_phone_number = removeSpaces(values.mobile_phone_number)
        onFinish({...values});
    };

i also tried this :
const handleSubmitUsersEdit = (values: FieldValues) => {
        onFinish({...values, mobile_phone_number: removeSpaces(values.mobile_phone_number)});
    };

but i always have the same issue which is : edit.tsx:90 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'split') or replace in the other case.
My question is : How edit the phone number to remove the spaces before i submit it to the API ?
Was this page helpful?