Clear Dropdown selected Key after submit the form.
Hi All,
I want to clear the selected key value after complete submission the form. I'm used Dropdown office ui febric control and able to bind datasource to the control. I want to be clear the selected value after submit the form data.
Here's my code:
`import { Dropdown, IDropdown, DropdownMenuItemType, IDropdownOption } from 'office-ui-fabric-react'; let _Drpitems: IDrpItem[] = [];
const { DrpItems,selectedItem } = this.state; <Dropdown label="Status:" id="drpcolumn" selectedKey={ selectedItem ? selectedItem.key : undefined} onChanged={(e) => this.changeState(e)} options={DrpItems} /> `
bind DrpItems state array through following method
private _getStatusChoiceData() { sp.web.lists.getByTitle("Demo Details").fields.getByInternalNameOrTitle("Status").get().then(f => { _Drpitems = []; for (let choice of f.Choices) { var _DemoItem: IDrpItem = { key: choice, text: choice }; _Drpitems.push(_DemoItem); this.setState({ DrpItems: _Drpitems }) } }); `
private Cleancontroldata() { this.setState({ Title: "", PeopickerItems: [], selectedItem: null, }); }
I've reset the state value with null however dropdown has selected value and not to be clear.
similar to #5473 the nature of an HTML dropdown is that once a value is selected there is no way to get back to the placeholder. One option many HTML forms use is to not use a placeholder, but use the first value of the dropdown as the default, non selected value. We're looking to do a major overhaul of the dropdown and combobox in the near future, and i'm sure that this topic will come up.
This issue has been automatically marked as stale because it has marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your contributions to Fabric React!
@micahgodbolt - Sound like I need to reset with default option select key rather than going to set null on the State value. I''ll implement this soon and close it. Thanks!