question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Field won't update

See original GitHub issue

Hi there,

I am sure this is my error, but I cannot get my text input to update:

import * as React from 'react'
import Revalidation from 'revalidation'


const SubmitForm = ({
  reValidation: { form, validate, valid, errors, validateAll },
  onSubmit
}) =>
  <form>
    <div className="formGroup">
      <label>Name</label>
      <input
        type="text"
        value={form.name}
        onChange={e => validate('name', e.target.value)}
      />
      {errors.name}
    </div>
    <p>{valid.toString()}</p>
    <button onClick={() => validateAll(onSubmit)}>Submit</button>
  </form>

const isGreaterThan = a => b => b > a
const ErrorComponent = ({ errorMsgs }) =>
  <div className="error">{errorMsgs.shift()}</div>
const validationRules = {
  name: [[isGreaterThan(5), `Minimum Name length of 6 is required.`]]
}
const initialState = { name: 'Alex' }
const enhanced = Revalidation(initialState, validationRules, ErrorComponent, {
  validateSingle: false
})
const EnhancedSubmitForm = enhanced(SubmitForm)

class SubmitPage extends React.Component<any, any> {
  constructor(props) {
    super(props)
    this.state = { form: { name: 'Alex' } }
  }
  onSubmit(e) {
    e.preventDefault()
    alert('submitted')
  }
  render() {
    return (
      <EnhancedSubmitForm onSubmit={this.onSubmit} form={this.state.form} />
    )
  }
}
export default SubmitPage

In the above example, I see the initial value "Alex" but when I type in that field, nothing happens? Looking at the example, I would have thought reValidate.validate would in turn update reValidate.form.name?

I am sure this is my understanding, hopefully I can contribute to the documentation after 😃!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bookercodescommented, Jun 20, 2017

Oh yeah, that would explain why validateAll wasn’t working ha - I moved button.onClick to form.onSubmit and now I have a nicely validated form

1reaction
bookercodescommented, Jun 20, 2017

Sorry, that is another “me” problem. I needed to to be comparing the length so I updated isGreaterThan to

const isGreaterThan = a => b => b > a

And now it all works 🎉

Read more comments on GitHub >

github_iconTop Results From Across the Web

Some fields are updated while other fields are not
Click the Update fields check box, and then click OK. Microsoft Office Word 2007. Click the Microsoft Office Button, and then click Word...
Read more >
Word: Fields won't update | CyberText Newsletter
Word: Fields won't update · Press Ctrl+Shift+F11 on the locked field to unlock it. · To unlock ALL fields in the document, press...
Read more >
Fields Won't Update when Printing - Word Ribbon Tips
First, try to determine if all the fields fail to automatically update. In other words, if you have 30 fields in your document...
Read more >
Solved: Field won't update - ServiceNow Community
I have a custom deal table with a bunch of records with fields that will revert back to the original value after trying...
Read more >
Fields within block won't update - Civil 3D - Autodesk Forums
Please check in Options, User Preference tab, Field Update Settings... (lower left of dialog) and make sure appropriate boxes are checked. Tags ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found