add support for an onSubmit action for the input widget (#2749)
This commit is contained in:
parent
4ccdba9e85
commit
b8bcac8544
|
|
@ -17,7 +17,9 @@ describe("Binding the multiple Widgets and validating NavigateTo Page", function
|
||||||
it("Input widget test with default value from table widget", function() {
|
it("Input widget test with default value from table widget", function() {
|
||||||
cy.openPropertyPane("inputwidget");
|
cy.openPropertyPane("inputwidget");
|
||||||
cy.get(widgetsPage.defaultInput).type(testdata.defaultInputWidget);
|
cy.get(widgetsPage.defaultInput).type(testdata.defaultInputWidget);
|
||||||
cy.get(widgetsPage.actionSelect).click();
|
cy.get(widgetsPage.actionSelect)
|
||||||
|
.first()
|
||||||
|
.click();
|
||||||
cy.get(commonlocators.chooseAction)
|
cy.get(commonlocators.chooseAction)
|
||||||
.children()
|
.children()
|
||||||
.contains("Navigate To")
|
.contains("Navigate To")
|
||||||
|
|
|
||||||
|
|
@ -1262,7 +1262,9 @@ Cypress.Commands.add("togglebarDisable", (value) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Cypress.Commands.add("getAlert", (alertcss) => {
|
Cypress.Commands.add("getAlert", (alertcss) => {
|
||||||
cy.get(commonlocators.dropdownSelectButton).click({ force: true });
|
cy.get(commonlocators.dropdownSelectButton)
|
||||||
|
.first()
|
||||||
|
.click({ force: true });
|
||||||
cy.get(widgetsPage.menubar)
|
cy.get(widgetsPage.menubar)
|
||||||
.contains("Show Message")
|
.contains("Show Message")
|
||||||
.click({ force: true })
|
.click({ force: true })
|
||||||
|
|
|
||||||
|
|
@ -136,6 +136,22 @@ class InputComponent extends React.Component<
|
||||||
return "text";
|
return "text";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
onKeyDownTextArea = (e: React.KeyboardEvent<HTMLTextAreaElement>) => {
|
||||||
|
const isEnterKey = e.key === "Enter" || e.keyCode === 13;
|
||||||
|
const { disableNewLineOnPressEnterKey } = this.props;
|
||||||
|
if (isEnterKey && disableNewLineOnPressEnterKey && !e.shiftKey) {
|
||||||
|
e.preventDefault();
|
||||||
|
}
|
||||||
|
if (typeof this.props.onKeyDown === "function") {
|
||||||
|
this.props.onKeyDown(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
onKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if (typeof this.props.onKeyDown === "function") {
|
||||||
|
this.props.onKeyDown(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private numericInputComponent = () => (
|
private numericInputComponent = () => (
|
||||||
<NumericInput
|
<NumericInput
|
||||||
value={this.props.value}
|
value={this.props.value}
|
||||||
|
|
@ -155,6 +171,7 @@ class InputComponent extends React.Component<
|
||||||
stepSize={this.props.stepSize}
|
stepSize={this.props.stepSize}
|
||||||
onFocus={() => this.setFocusState(true)}
|
onFocus={() => this.setFocusState(true)}
|
||||||
onBlur={() => this.setFocusState(false)}
|
onBlur={() => this.setFocusState(false)}
|
||||||
|
onKeyDown={this.onKeyDown}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
private textAreaInputComponent = () => (
|
private textAreaInputComponent = () => (
|
||||||
|
|
@ -169,6 +186,7 @@ class InputComponent extends React.Component<
|
||||||
growVertically={false}
|
growVertically={false}
|
||||||
onFocus={() => this.setFocusState(true)}
|
onFocus={() => this.setFocusState(true)}
|
||||||
onBlur={() => this.setFocusState(false)}
|
onBlur={() => this.setFocusState(false)}
|
||||||
|
onKeyDown={this.onKeyDownTextArea}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -199,6 +217,7 @@ class InputComponent extends React.Component<
|
||||||
type={this.getType(this.props.inputType)}
|
type={this.getType(this.props.inputType)}
|
||||||
onFocus={() => this.setFocusState(true)}
|
onFocus={() => this.setFocusState(true)}
|
||||||
onBlur={() => this.setFocusState(false)}
|
onBlur={() => this.setFocusState(false)}
|
||||||
|
onKeyDown={this.onKeyDown}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
private renderInputComponent = (inputType: InputType, isTextArea: boolean) =>
|
private renderInputComponent = (inputType: InputType, isTextArea: boolean) =>
|
||||||
|
|
@ -267,6 +286,12 @@ export interface InputComponentProps extends ComponentProps {
|
||||||
isInvalid: boolean;
|
isInvalid: boolean;
|
||||||
showError: boolean;
|
showError: boolean;
|
||||||
onFocusChange: (state: boolean) => void;
|
onFocusChange: (state: boolean) => void;
|
||||||
|
disableNewLineOnPressEnterKey?: boolean;
|
||||||
|
onKeyDown?: (
|
||||||
|
e:
|
||||||
|
| React.KeyboardEvent<HTMLTextAreaElement>
|
||||||
|
| React.KeyboardEvent<HTMLInputElement>,
|
||||||
|
) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default InputComponent;
|
export default InputComponent;
|
||||||
|
|
|
||||||
|
|
@ -725,6 +725,15 @@ const PropertyPaneConfigResponse: PropertyPaneConfigsResponse["data"] = {
|
||||||
controlType: "ACTION_SELECTOR",
|
controlType: "ACTION_SELECTOR",
|
||||||
isJSConvertible: true,
|
isJSConvertible: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
id: "5.11.3",
|
||||||
|
helpText:
|
||||||
|
"Triggers an action on submit (when the enter key is pressed)",
|
||||||
|
propertyName: "onSubmit",
|
||||||
|
label: "onSubmit",
|
||||||
|
controlType: "ACTION_SELECTOR",
|
||||||
|
isJSConvertible: true,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ class InputWidget extends BaseWidget<InputWidgetProps, WidgetState> {
|
||||||
static getTriggerPropertyMap(): TriggerPropertiesMap {
|
static getTriggerPropertyMap(): TriggerPropertiesMap {
|
||||||
return {
|
return {
|
||||||
onTextChanged: true,
|
onTextChanged: true,
|
||||||
|
onSubmit: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -136,6 +137,22 @@ class InputWidget extends BaseWidget<InputWidgetProps, WidgetState> {
|
||||||
this.props.updateWidgetMetaProperty("isFocused", focusState);
|
this.props.updateWidgetMetaProperty("isFocused", focusState);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
handleKeyDown = (
|
||||||
|
e:
|
||||||
|
| React.KeyboardEvent<HTMLTextAreaElement>
|
||||||
|
| React.KeyboardEvent<HTMLInputElement>,
|
||||||
|
) => {
|
||||||
|
const isEnterKey = e.key === "Enter" || e.keyCode === 13;
|
||||||
|
if (isEnterKey && this.props.onSubmit) {
|
||||||
|
super.executeAction({
|
||||||
|
dynamicString: this.props.onSubmit,
|
||||||
|
event: {
|
||||||
|
type: EventType.ON_SUBMIT,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
getPageView() {
|
getPageView() {
|
||||||
const value = this.props.text || "";
|
const value = this.props.text || "";
|
||||||
const isInvalid =
|
const isInvalid =
|
||||||
|
|
@ -149,6 +166,7 @@ class InputWidget extends BaseWidget<InputWidgetProps, WidgetState> {
|
||||||
if (this.props.maxChars) conditionalProps.maxChars = this.props.maxChars;
|
if (this.props.maxChars) conditionalProps.maxChars = this.props.maxChars;
|
||||||
if (this.props.maxNum) conditionalProps.maxNum = this.props.maxNum;
|
if (this.props.maxNum) conditionalProps.maxNum = this.props.maxNum;
|
||||||
if (this.props.minNum) conditionalProps.minNum = this.props.minNum;
|
if (this.props.minNum) conditionalProps.minNum = this.props.minNum;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<InputComponent
|
<InputComponent
|
||||||
value={value}
|
value={value}
|
||||||
|
|
@ -168,6 +186,8 @@ class InputWidget extends BaseWidget<InputWidgetProps, WidgetState> {
|
||||||
stepSize={1}
|
stepSize={1}
|
||||||
onFocusChange={this.handleFocusChange}
|
onFocusChange={this.handleFocusChange}
|
||||||
showError={!!this.props.isFocused}
|
showError={!!this.props.isFocused}
|
||||||
|
disableNewLineOnPressEnterKey={!!this.props.onSubmit}
|
||||||
|
onKeyDown={this.handleKeyDown}
|
||||||
{...conditionalProps}
|
{...conditionalProps}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
@ -215,6 +235,7 @@ export interface InputWidgetProps extends WidgetProps, WithMeta {
|
||||||
isRequired?: boolean;
|
isRequired?: boolean;
|
||||||
isFocused?: boolean;
|
isFocused?: boolean;
|
||||||
isDirty?: boolean;
|
isDirty?: boolean;
|
||||||
|
onSubmit?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default InputWidget;
|
export default InputWidget;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user