3

I have a component

export default function AppTextInput({icon, placeholder,onChangeText, ...otherProps}) {

  const  onChanged =(text) =>{
      let newText = '';
      let numbers = '0123456789';
      for (var i=0; i < text.length; i++) {

              if (numbers.indexOf(text[i]) > -1) {
                  newText = newText + text[i];
              } else {
                  alert("please enter integer numbers only");

              }
      }

    }

    return (

        <View style={styles.container}>
            {icon &&
                <MaterialCommunityIcons style={{marginRight: 10}} name={icon} color={colors.grayMedium} size={20}/>}
            <TextInput style={defaultStyles.text} placeholder={placeholder}
                       onChangeText={(text)=> onChanged(text)}  maxLength={3} {...otherProps}
            ></TextInput>
        </View>
    )
}

and use of component

<View style={{top: -80}}>
    <AppTextInput icon="timer-sand"  placeholder={"Prep Time"} keyboardType='numeric' onChangeText={(text) => setPrepTime(text)}/>
    <AppTextInput icon="timer" placeholder={"Round Duration"} keyboardType='number-pad' onChangeText={(text) => setRoundDuration(text)}/>
    <AppTextInput icon="timer" placeholder={"Break Duration"} keyboardType='number-pad' onChangeText={(text) => setBreakDuration(text)}/>
    <AppTextInput icon="repeat" placeholder={"Number of Rounds"} keyboardType='number-pad'  onChangeText={(text) => setNumRounds(text)}/>
    <AppTextInput icon="format-list-numbered" placeholder={"Number of Sets"} keyboardType='number-pad' onChangeText={(text) => setNumSets(text)}/>
    {exerciseInputEles}
</View>

but when i input values ,alert vorks,but onChangeText={(text) => setNumSets(text)} and other don't see my input, why

what should i change that alert work and all onChangeText={(text) => setNumSets(text)} next input see my input?

i don't now what to try more to fix this or create current input

2 Answers 2

1

Do it this way:

   <AppTextInput icon="timer-sand"  placeholder={"Prep Time"} keyboardType='numeric' setPrepTime={setPrepTime}/>

and in appTextInput modify as below:

export default function AppTextInput({icon, placeholder,onChangeText,setPrepTime ...otherProps}) {



const  onChanged =(text) =>{
      let newText = '';
      let numbers = '0123456789';
      for (var i=0; i < text.length; i++) {

              if (numbers.indexOf(text[i]) > -1) {
                  newText = newText + text[i];
                  setPrepTime(newText)
              } else {
                  alert("please enter integer numbers only");

              }
      }

    }

    return (

        <View style={styles.container}>
            {icon &&
                <MaterialCommunityIcons style={{marginRight: 10}} name={icon} color={colors.grayMedium} size={20}/>}
            <TextInput style={defaultStyles.text} placeholder={placeholder}
                       onChangeText={(text)=> onChanged(text)}  maxLength={3} {...otherProps}
            ></TextInput>
        </View>
    )
}
Sign up to request clarification or add additional context in comments.

7 Comments

after entering the last number, a list of exercises equal to this number should open, but it does not open with this solution
if i delete onchangetext ,setpreptime and <AppTextInput icon="timer-sand" placeholder={"Prep Time"} keyboardType='numeric' onChangeText={(text) => setPrepTime(text)}/> use that it open but current input don't work
what do you mean can you clarify?
it's hard to explain, mb we can meet in telegram and you will see all my project?
|
1

Make this changes

  1. component
    export default function AppTextInput({icon, placeholder,onChangeText, ...otherProps}) {
    
      const  onChanged =(text) =>{
          let newText = '';
          let numbers = '0123456789';
          for (var i=0; i < text.length; i++) {
    
                  if (numbers.indexOf(text[i]) > -1) {
                      newText = newText + text[i];
                      onChangeText(text)
                  } else {
                      alert("please enter integer numbers only");
    
                  }
          }
    
        }
    
        return (
    
            <View style={styles.container}>
                {icon &&
                    <MaterialCommunityIcons style={{marginRight: 10}} name={icon} color={colors.grayMedium} size={20}/>}
                <TextInput style={defaultStyles.text} placeholder={placeholder}
                           onChangeText={onChanged}  maxLength={3} {...otherProps}
                />
            </View>
        )
    }

Use: add your state variable in the value tag I've added possible guess of name that you might have but it's not you can change it to your respective state name

<View style={{top: -80}}>
    <AppTextInput icon="timer-sand"  placeholder={"Prep Time"} keyboardType='numeric' value={prepTime} onChangeText={setPrepTime}/>
    <AppTextInput icon="timer" placeholder={"Round Duration"} keyboardType='number-pad' value={roundDuration} onChangeText={setRoundDuration}/>
    <AppTextInput icon="timer" placeholder={"Break Duration"} keyboardType='number-pad' value={breakDuration} onChangeText={setBreakDuration}/>
    <AppTextInput icon="repeat" placeholder={"Number of Rounds"} keyboardType='number-pad'  value={numRounds} onChangeText={setNumRounds}/>
    <AppTextInput icon="format-list-numbered" placeholder={"Number of Sets"} keyboardType='number-pad' value={numSets} onChangeText={setNumSets}/>
    {exerciseInputEles}
</View>

1 Comment

Can you help me to do that , after alert , full clear text edit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.