Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
<input> value is not recognized

So the problem is when the input value is auto-filled and when I click submit button input field value is not recognized unless I change something in there for example delete and add again the last word to the first name. How can I make value recognized immediately?

    // This is 'context' from where we get info about 'user' like first name, last 
    // name, email etc

    const { user } = useContext(UserContext);
    const [firstName, changeFirstName] = useState(user.firstName);
    const [lastName, changeLastName] = useState(user.lastName);

    /**
     * @param {Object} e 
     */
    const handleChange = (e) => {
        handleUserInputChange(e);
        changeFirstName(e.firstName);
        changeLastName(e.lastName);
    }
       
    <input
        type="text"
        value={firstName}
        name="firstName"
        onChange={(e) => handleChange(e)}
    />
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

There is something fishy with your onChange handler:

const handleChange = (e) => {
  handleUserInputChange(e);
  changeFirstName(e.firstName);
  changeLastName(e.lastName);
}

At this point, you don't have access to the e.firstName and e.lastName values. The e object is just the event from the onChange call (find an example in the React docs here).

For the first name, you could instead use something like this:

const handleChange = (e) => {
  changeFirstName(e.target.value);
}
about 4 years ago · Juan Pablo Isaza Report

0

I would recommend refactoring a little bit to make it more understandable. Anyway, you are looking to (input)="" to change the value as user types. You can't have property as a const (constant) if you play to overwrite it.

html

    <input #firstName
        type="text"
        (value)="firstName"
        name="firstName"
        (input)="onFirstNameChange(firstName.value)"/>

    <input #lastName
        type="text"
        (value)="lastName"
        name="lastName"
        (input)="onLastNameChange(lastName.value)"/>

ts

firstName: string;
lastName: string;

onFirstNameChange(event: any) {
  this.firstName = event;
}

onLastNameChange(event: any) {
  this.firstName = event;
}  
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!