In my app, using react, SPFX 1.8 and office-ui-fabric-react 6.189.2 i want to manage onSelectDate on a dynamic created control that it's part of a table.
I already found a walkaround with a dropdown using the id html property of the control to know the element to modify on state, but i can´t have the Form Event or get other props for the DatePickerControl. How can I achieve this on the React right way? I want to change the state for the needed element.
{///Function to create elements
private _renderTable(): React.ReactNode {
return (<div>
<table >
<thead>
<td>Title</td>
<td>DropDown</td>
<td>DatePicker</td>
</thead>
<tbody>
{this.state.elements.map( x=> {
return((<tr key={"item" + x.Id}>
<td>{x.Title} </td>
<td><Dropdown
id= {"DropD" + x.Id}
placeholder="Select an option"
selectedKey={this.state.elements.filter(item=> x.Id === item.Id )[0].DropDownField?this.state.elements.filter(item=> x.Id === item.Id )[0].DropDownField.Id:0}
label=""
onChange ={this.handleDropDown}
options={this.state.DropDownOptions.map(item=>
{return
{key:item.Id, text:item.Title};})}
style={{ width:"150px"}} /></td>
<td>
<DatePicker
style={{display:"inline-block"}}
onSelectDate={this._onChangeDPicker}
firstDayOfWeek = {DayOfWeek.Sunday}
strings = {DayPickerStrings}
placeholder="Select Date"
value={this.state.elements.filter(item=>
x.Id === item.Id)[0].DateField}
/>
);
});
}
///Function to DatePicker
private _onChangeDPicker(date: Date | null | undefined) {
///// ????????
// this.setState({
// ??????????
// });
}
///Function to manage DropDown
private handleDropDown(event: React.FormEvent<HTMLDivElement>, option: IDropdownOption, index?: number) {
const auxDropDownOptions= this.state.DropDownOptions.filter(t=> t.Id === option.key)[0];
let auxId = parseInt(event.target["id"].replace("DropD", ""));
let auxArray = this.state.elements;
auxArray.filter(x=> x.Id === auxId)[0].DropDownField= auxDropDownOptions;
this.setState({
elements: auxArray,
});
return;
}
}