diff --git a/src/ImageRunModal.jsx b/src/ImageRunModal.jsx index b875db75c..5f8730b8f 100644 --- a/src/ImageRunModal.jsx +++ b/src/ImageRunModal.jsx @@ -2,6 +2,7 @@ import React from 'react'; import { Button } from "@patternfly/react-core/dist/esm/components/Button"; import { Checkbox } from "@patternfly/react-core/dist/esm/components/Checkbox"; import { Form, FormGroup } from "@patternfly/react-core/dist/esm/components/Form"; +import { FormHelper } from "cockpit-components-form-helper.jsx"; import { FormSelect, FormSelectOption } from "@patternfly/react-core/dist/esm/components/FormSelect"; import { Grid, GridItem } from "@patternfly/react-core/dist/esm/layouts/Grid"; import { Modal } from "@patternfly/react-core/dist/esm/components/Modal"; @@ -258,7 +259,7 @@ export class ImageRunModal extends React.Component { }; async onCreateClicked(runImage = false) { - if (!this.validateForm()) + if (!await this.validateForm()) return; const Dialogs = this.props.dialogs; @@ -591,8 +592,17 @@ export class ImageRunModal extends React.Component { return Object.keys(validationFailed).length == 0; }; - validateForm = () => { - const { publish, volumes, env } = this.state; + async validateContainerName(containerName) { + try { + await client.containerExists(this.isSystem(), containerName); + } catch (error) { + return; + } + return _("Name already in use"); + } + + async validateForm() { + const { publish, volumes, env, containerName } = this.state; const validationFailed = { }; const publishValidation = publish.map(a => { @@ -626,10 +636,15 @@ export class ImageRunModal extends React.Component { if (envValidation.some(entry => Object.keys(entry).length > 0)) validationFailed.env = envValidation; + const containerNameValidation = await this.validateContainerName(containerName); + + if (containerNameValidation) + validationFailed.containerName = containerNameValidation; + this.setState({ validationFailed }); return this.isFormValid(validationFailed); - }; + } /* Updates a validation object of the whole dynamic list's form (e.g. the whole port-mapping form) * @@ -704,12 +719,22 @@ export class ImageRunModal extends React.Component { const defaultBody = (