diff --git a/src/fireedge/src/client/components/Forms/ServiceTemplate/CreateForm/Steps/Roles/rolesPanel.js b/src/fireedge/src/client/components/Forms/ServiceTemplate/CreateForm/Steps/Roles/rolesPanel.js index 4572fd1818..551f84102c 100644 --- a/src/fireedge/src/client/components/Forms/ServiceTemplate/CreateForm/Steps/Roles/rolesPanel.js +++ b/src/fireedge/src/client/components/Forms/ServiceTemplate/CreateForm/Steps/Roles/rolesPanel.js @@ -42,7 +42,7 @@ const RoleVmVmPanel = ({ roles, onChange, selectedRoleIndex }) => { const handleTextFieldChange = (event) => { const { name, value } = event.target - handleInputChange(name, value) + handleInputChange(name, parseInt(value, 10)) } const handleAutocompleteChange = (event, value) => { diff --git a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/graphicsSchema.js b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/graphicsSchema.js index b4f8ff86f5..f793e12872 100644 --- a/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/graphicsSchema.js +++ b/src/fireedge/src/client/components/Forms/VmTemplate/CreateForm/Steps/ExtraConfiguration/inputOutput/graphicsSchema.js @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * * limitations under the License. * * ------------------------------------------------------------------------- */ -import { ObjectSchema, boolean, lazy, string } from 'yup' +import { ObjectSchema, boolean, lazy, string, mixed } from 'yup' import { HYPERVISORS, INPUT_TYPES, T } from 'client/constants' import { @@ -71,10 +71,21 @@ export const TYPE = (isUpdate) => ({ type: INPUT_TYPES.SWITCH, label: T.Vnc, dependOf: ['HYPERVISOR', '$general.HYPERVISOR'], - validation: boolean() - .notRequired() + validation: mixed() + .default(() => (isUpdate ? undefined : true)) .afterSubmit((value, { context }) => (value ? 'VNC' : undefined)) - .default(() => (isUpdate ? undefined : true)), + .test('is-valid-type', 'Invalid value', function (value) { + if ( + typeof value === 'boolean' || + value === 'VNC' || + value === undefined + ) { + return true + } + + return false + }), + grid: { md: 12 }, }) diff --git a/src/fireedge/src/client/utils/translation.js b/src/fireedge/src/client/utils/translation.js index d0102ab1be..b19a37a34e 100644 --- a/src/fireedge/src/client/utils/translation.js +++ b/src/fireedge/src/client/utils/translation.js @@ -20,6 +20,7 @@ import { number, string, boolean, + mixed, object, array, date, @@ -29,26 +30,28 @@ import { T } from 'client/constants' import { isDivisibleBy, isBase64 } from 'client/utils/number' const buildMethods = () => { - ;[number, string, boolean, object, array, date].forEach((schemaType) => { - addMethod(schemaType, 'afterSubmit', function (fn) { - this._mutate = true // allows to mutate the initial schema - this.submit = (...args) => - typeof fn === 'function' ? fn(...args) : args[0] + ;[number, string, boolean, mixed, object, array, date].forEach( + (schemaType) => { + addMethod(schemaType, 'afterSubmit', function (fn) { + this._mutate = true // allows to mutate the initial schema + this.submit = (...args) => + typeof fn === 'function' ? fn(...args) : args[0] - return this - }) - addMethod(schemaType, 'cast', function (value, options = {}) { - const resolvedSchema = this.resolve({ value, ...options }) - let result = resolvedSchema._cast(value, options) + return this + }) + addMethod(schemaType, 'cast', function (value, options = {}) { + const resolvedSchema = this.resolve({ value, ...options }) + let result = resolvedSchema._cast(value, options) - if (options.isSubmit) { - const needChangeAfterSubmit = typeof this.submit === 'function' - needChangeAfterSubmit && (result = this.submit(result, options)) - } + if (options.isSubmit) { + const needChangeAfterSubmit = typeof this.submit === 'function' + needChangeAfterSubmit && (result = this.submit(result, options)) + } - return result - }) - }) + return result + }) + } + ) addMethod(boolean, 'yesOrNo', function (addAfterSubmit = true) { const schema = this.transform(function (value) { return !this.isType(value) ? String(value).toUpperCase() === 'YES' : value