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.

Modify Form to support an array of FieldValues

See original GitHub issue

I would like to be able to have Form control an array of inputs. For instance, if I have a form where I am allowing a user to input multiple phone numbers.

Expected Behavior

Originally I thought this would have worked by making the name of the controlled component with the index of the FieldValue. Something like phones[0].number which would be an object.

Actual Behavior

It does not work like this, instead I have to implement my own array of FieldValues, and control them using external state.

URL, screen shot, or Codepen exhibiting the issue

Here is my code sandbox with a demonstration of the issue.

Your Environment

  • Grommet version: 2.11.1
  • Browser Name and version: Brave Version 1.4.96 Chromium: 80.0.3987.132 (Official Build) (64-bit)
  • Operating System and version (desktop or mobile): macOS Catalina 10.15.3

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ericsoderberghpcommented, Mar 16, 2020

Sounds reasonable. My inclination is to have FormContext.update() know how to translate a name like person[0].name into setting value['person'][0]['name'] = value.

1reaction
jcfilbencommented, Sep 21, 2021

Go for it! @g4rry420

Read more comments on GitHub >

github_iconTop Results From Across the Web

forms - How to examine existing field values and modify other ...
Check the $form array instead for the default value of the desired field, then use the states to add some behavior. Share.
Read more >
jQuery compare select field values with an array before ...
I'm trying to get the values of this select field and compare it against a list of cities I have, if found any...
Read more >
useFieldArray - Simple React forms validation
Performant, flexible and extensible forms with easy-to-use validation.
Read more >
Update form field values in WPForms - Bill Erickson
$entry – (array) Original $_POST global. $form_data – (array) Form settings/data. Example. My form uses number fields for Red Shirts and Blue ...
Read more >
array field on form - ServiceNow Community
Can anybody help me on this? ... array field on form ... parse the strings using a fieldValue.split(','); assuming fieldValue already holds ...
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