Skip to content

Commit

Permalink
Add the ability to get updates of the form state in table
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Mar 15, 2024
1 parent 8b9e08c commit 7bb0248
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions otoroshi/javascript/src/components/inputs/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ export class Form extends Component {
};

changeValue = (name, value) => {
const oldValue = cloneDeep(this.theValue());
const newValue = cloneDeep(this.theValue());
deepSet(newValue, name, value);
this.props.onChange(newValue);
if (this.props.onStateChange) {
this.props.onStateChange(newValue, oldValue, this.props.onChange)
}
//if (name.indexOf('.') > -1) {
// const [key1, key2] = name.split('.');
// const newValue = {
Expand Down
4 changes: 4 additions & 0 deletions otoroshi/javascript/src/components/inputs/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ export class Table extends Component {
style={{ paddingTop: '30px', ...this.props.style }}
>
{React.createElement(this.props.formComponent, {
onStateChange: this.props.onStateChange,
showAdvancedForm: true,
//this.state.showAdvancedForm, // advanced view in creation mode
onChange: (currentItem) => {
Expand Down Expand Up @@ -734,6 +735,7 @@ export class Table extends Component {
/>
) : (
<Form
onStateChange={this.props.onStateChange}
value={this.state.currentItem}
onChange={(currentItem) => this.setState({ currentItem })}
flow={this.props.formFlow}
Expand Down Expand Up @@ -772,6 +774,7 @@ export class Table extends Component {
: null,
<form className="form-horizontal" style={{ paddingTop: '30px', ...this.props.style }}>
{React.createElement(this.props.formComponent, {
onStateChange: this.props.onStateChange,
onChange: (currentItem) => {
this.setState({ currentItem });

Expand Down Expand Up @@ -810,6 +813,7 @@ export class Table extends Component {
/>
) : (
<Form
onStateChange={this.props.onStateChange}
value={this.state.currentItem}
onChange={(currentItem) => this.setState({ currentItem })}
flow={this.props.formFlow}
Expand Down

0 comments on commit 7bb0248

Please sign in to comment.