简体   繁体   中英

Conversational Form with React. How to make multiple choice?

I am working with React(Next.js). I have a good example [https://codepen.io/space10/pen/JMXzGX][1] how to use multiple choise in simple HTML, but how to use it in React?

Here is my code
在此处输入图像描述

Here what I have in browser[1]:https://i.stack.imgur.com/bWLjG.png

Just keep adding objects into the array - as long as the name is the same, it seems to combine it.

Working Demo: https://stackblitz.com/edit/react-conversational-form-with-radio

    this.formFields = [
      {
        'tag': 'input',
        'type': 'radio',
        'name': 'country',
        'cf-questions': 'What is your country?',
        'cf-label': 'ukraine',
        'value': 'ukraine',
      },
      {
        'tag': 'input',
        'type': 'radio',
        'name': 'country',
        'cf-label': 'india',
        'value': 'india',
      },
      {
        'tag': 'input',
        'type': 'radio',
        'name': 'country',
        'cf-label': 'sri lanka',
        'value': 'sri lanka',
      },
      {
        'tag': 'input',
        'type': 'text',
        'name': 'lastname',
        'cf-questions': 'What is your lastname?'
      }
    ];

Returns the form result something like this:

{ country: ["ukraine"], lastname: 'tasdasd' }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM