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.

cerebral-forms issues

See original GitHub issue

Form factory has wrong documentation . hasValue, isPristine, isValid, errorMessage will be ignored and overwriten. Anyway, form factory returns lot of useless fields to be stored in state even if user doesn’t needs it.

{
  value: '', // must be always present, it's ok now
  validationRules: null, // should be omitted if not passed to form factory
  validationMessages: null, // should be omitted if not passed to form factory
  isRequired: false, // should be omitted if not passed to form factory
  requiredMessage: null, // should be omitted if not passed to form factory
  isValueRules: ['isValue'], // should only present if isRequired passed to form factory
  defaultValue: '', // seems ok, but I would rename it to initialValue and made it optional
  hasValue: false, // should never be in state, it is computed
  isPristine: true, //should be in state, and set to false by changeField
  isValid: true, // should never be in state, it is computed
  errorMessage: null, // should never be in state, it is computed
}

so when I call form({field: {value}}) I expect only minimal state in my state-tree:

{
  value: '',
  defaultValue: '',
  isPristine: true
}

Few more notes:

  • should have better example for isTouched, maybe even demo implementation
  • Set a default value for the whole form contains a typo (newForm)
  • Custom global props should go before Set a default value for the whole form where it used
  • to make changeField be more composable it should accept params:
changeField(input`field`, input`value`)
// or
changeField(state`path.to.field`, input`value`)
  • changeField is different from set, because it operates with value property and sets isDirty
  • no need to run any validation on changeField since it can be computed
  • validateField ans validateForm action factories is extraneous, see above 😃
  • formToJSON should have operator equivalent:
set(input`formValues`, form`pathToForm`)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:17 (17 by maintainers)

github_iconTop GitHub Comments

4reactions
christianalfonicommented, Feb 27, 2017

New forms specification:

// No factory, just write out the supported state structure
{
  state: {
    form: {
      firstName: {
        value: '',
        validationRules: ['minLength:3']
      }
    }
  }
}

// Is a provider

Controller({
  providers: [FormsProvider({
    rules: {
      newRule (value, form, arg) {}
    }
  })]
})

// Use a computed to point to the form
connect({
  form: form(state`path.to.form`)
},
  function MyForm ({form}) {
    form.isValid
    form.firstName.isValid
    
    // Should not define text resources in state, should be in component
    form.firstName.failedRuleIndex

    form.firstName.value

    form.getInvalidFields()
    form.toJSON()
  }
)

// provider in actions
function someAction ({forms}) {
  forms.get('path.to.form')
  forms.addRule('name', () => {}) // Dynamically add rule
  forms.reset('path.to.form') // Reset to defaults
}

That means we can drop a lot of factories cause there is no validation happening inside the state tree anymore.

2reactions
Guriacommented, Feb 6, 2017

@christianalfoni please post here revisited blueprint for new forms getting in mind latest API changes

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cerebral Atrophy | National Institute of Neurological Disorders ...
Symptoms of cerebral atrophy: Many diseases that cause cerebral atrophy are associated with dementia, seizures, and a group of language ...
Read more >
Brain Disorders: Causes, Symptoms, and Diagnosis - Healthline
There are different brain disorders that can be caused by illness, genetics, or injury. Each comes with different risks, diagnoses, and treatment.
Read more >
Brain Lesions: Causes, Symptoms, Treatments - WebMD
Brain lesions can be caused by injury, infection, exposure to certain chemicals, problems with the immune system, and more.
Read more >
Cephalic Disorders | Johns Hopkins Medicine
Many children with microcephaly may have an intellectual disability, as well as cerebral palsy, sensory disorders including vision problems, poor motor skills, ...
Read more >
Cerebral Atrophy Symptoms & Causes - Baptist Health
Brain disease in all forms affects as many as one in six Americans and cerebral atrophy ... If you or a loved one...
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