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.

Checkbox support / Dropdowns with multiple selection at a time

See original GitHub issue

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn’t find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google “How to X in FastAPI” and didn’t find any information.
  • I already read and followed all the tutorial in the docs and didn’t find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

from fastapi import UploadFile, File, Request, Query
app = FastAPI()
@app.get('/selections')
async def selection_and(_q : str= Query("regression", enum = ["regression", "classification"]), _p : str = Query("target", enum = ['target', 'response'])):
    return({"task": _q, "target": _p})

Description

Is there a way to create checkboxes based on dynamic user inputs with FastAPI and use the checkbox answers to further analyze. Also, looking for dropdowns/search bars with multiple selection to select variables. I am able to incorporate dropdowns with one selection at a time.

Already referred this: https://eugeneyan.com/writing/fastapi-html-checkbox-download/

Best Regards,

Operating System

Windows

Operating System Details

No response

FastAPI Version

0.68.0

Python Version

3.8

Additional Context

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Sagaryalcommented, Mar 26, 2022

@gauravgund I tried as following for multiple selection. And is working. Swagger-ui supports it as I mention in above comment. Swagger json requires ‘array’ type. For FastApi to generate ‘array’ type, we need to supply Array and for this case List/list worked.

from enum import Enum
from typing import List
from fastapi import Query

class MyEnums(str, Enum):
    item_1 = "item_1"
    item_2 = "item_2"
    item_3 = "item_3"

@api_routes.post('/single-multi-selection')
def singleMultiSelectionField(singleSelctionDropdown: MyEnums, multiSelctionDropdown: List[MyEnums] = Query(...)):
    singleDropdownValue = singleSelctionDropdown.value
    multiSelectionList = [item.value for item in multiSelctionDropdown]

Also you can check this issue. It provides more info on dropdowns.

0reactions
Sagaryalcommented, Mar 26, 2022

https://swagger.io/docs/open-source-tools/swagger-ui/customization/plugin-api/

Fastapi just makes use of swagger ui so you’ll get more support on their GitHub repo if you need it. Could you close out this issue as it is not to do with fastapi

Could you please elaborate how to integrate it in FastAPI? Swagger UI supports it as show here. /pet/findByStatus

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multi-select Dropdown List with Checkbox using jQuery
Multiselect dropdown is very useful to allow the user to select multiple options in a selectbox. Multiple selections of the dropdown list ...
Read more >
Multiselect Dropdown List With Checkboxes - multiselect.js
1. Include the stylesheet 'multiselect.css' in the head section of the webpage. · 2. Create a normal 'multiple' select element on the webpage....
Read more >
Multi-Select Checkbox Dropdown List - Create And Edit In ...
In this article, you will learn how to create a multi-select checkbox dropdown list in .NET core 3.1 and edit it.
Read more >
Dropdown, Multi-select dropdown, Checkbox, & Checklist
To filter the dataset field values based on any value chosen in another dropdown, set filter conditions choosing the field name instead of...
Read more >
Drop down multi select check box - jquery - Stack Overflow
How to bind drop down list along with checkbox values and multi select options using Jquery. I am trying to filter the Subcategory...
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