Commit d28218dc authored by Matija Obreza's avatar Matija Obreza Committed by Maksym Tishchenko
Browse files

Bug: in `withDialog` the first Button is executed when hitting Enter key

- Moved additional buttons after the default "Save" button
parent dd61f379
......@@ -13,7 +13,7 @@ export const url = (value) => empty(value) || value.match(/^(\w+:)\/\//g) ? unde
export const maxLength = (max) => (value) => empty(value) || value.length < max ? undefined : [ 'client:validations.maxCharacters', { count: max } ];
export const emailAddress = (value) => empty(value) || value.match(/^(?:[A-Za-z0-9!#$%&'*+\/=?^_\`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+\/=?^_\`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@([a-z0-9\-_]+\.)+([a-z]{2,4})$/) ? undefined : 'client:validations.invalidEmail';// eslint-disable-line
export const emailAddress = (value) => empty(value) || value === '' || value.match(/^(?:[A-Za-z0-9!#$%&'*+\/=?^_\`{|}~-]+(?:\.[A-Za-z0-9!#$%&'*+\/=?^_\`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@([a-z0-9\-_]+\.)+([a-z]{2,4})$/) ? undefined : 'client:validations.invalidEmail';// eslint-disable-line
export const minValue = (min) => (value) => (empty(value) || isNaN(value) || value >= min) ? undefined : [ 'client:validations.minValue', { min } ]; // `Should be greater or equal to ${min}`;
export const maxValue = (max) => (value) => (empty(value) || isNaN(value) || value <= max) ? undefined : [ 'client:validations.maxValue', { max } ]; // `Should be less or equal to ${min}`;
......
......@@ -101,12 +101,12 @@ class CooperatorDetailsPage extends React.Component<ICooperatorDetailsPage> {
this.resetError();
let cooperatorPromise: Promise<Cooperator>;
if (this.isSaveAsNew) {
if (this.isSaveAsNew || !formData.id) {
cooperatorPromise = CooperatorService.saveAsNew(formData)
} else {
cooperatorPromise = CooperatorService.updateCooperator(formData);
}
this.isSaveAsNew = false;
cooperatorPromise.then((cooperator) => {
this.closeCooperatorDialog();
receiveCooperatorSuccessAction(cooperator)
......
......@@ -66,8 +66,8 @@ const withDialog = (Component: React.ComponentType<any>) => {
<Component initialValues={ initialValues ?? {} } error={ error } { ...formExtraProps } />
</DialogContent>
<DialogActions>
{ ...additionalActions }
<Button type="submit" form={ formId } variant="contained" color="primary">{ submitButtonLabel || t('common:action.save') }</Button>
{ ...additionalActions }
<Button variant="text" color="primary" onClick={ onClose }>{ t('common:action.cancel') }</Button>
</DialogActions>
</Dialog>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment