1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

B OpenNebula/one#6707: Boolean default values on user inputs (#3215)

Signed-off-by: dcarracedo <dcarracedo@opennebula.io>
(cherry picked from commit 4a1abef990d9c970e8c07fe9b15202060d1b96d7)
This commit is contained in:
David 2024-09-05 11:34:37 +02:00 committed by Tino Vázquez
parent af05a4c991
commit 9ce5fc5fd8
No known key found for this signature in database
GPG Key ID: 14201E424D02047E
3 changed files with 26 additions and 8 deletions

View File

@ -115,15 +115,25 @@ const DEFAULT_VALUE_TEXT = {
name: 'defaultvalue',
label: T.DefaultValue,
dependOf: CA_TYPE.name,
htmlType: (type) => type === CA_TYPES.password && INPUT_TYPES.HIDDEN,
htmlType: (type) =>
(type === CA_TYPES.password || type === CA_TYPES.boolean) &&
INPUT_TYPES.HIDDEN,
type: getTypeProp,
fieldProps: getFieldProps,
validation: string(),
grid: { sm: 2.5, md: 2.5 },
}
const DEFAULT_VALUE_BOOLEAN = {
name: 'defaultvalue',
label: T.DefaultValue,
dependOf: CA_TYPE.name,
type: INPUT_TYPES.AUTOCOMPLETE,
htmlType: (type) => ![CA_TYPES.boolean].includes(type) && INPUT_TYPES.HIDDEN,
optionsOnly: true,
values: () => arrayToOptions(['NO', 'YES']),
fieldProps: getFieldProps,
validation: string(),
grid: { sm: 2.5, md: 2.5 },
}
@ -184,6 +194,7 @@ export const CUSTOM_ATTRIBUTES_FIELDS = [
NAME,
DESCRIPTION,
DEFAULT_VALUE_TEXT,
DEFAULT_VALUE_BOOLEAN,
MANDATORY,
DEFAULT_VALUE_RANGE_MIN,
DEFAULT_VALUE_RANGE_MAX,

View File

@ -15,6 +15,7 @@
* ------------------------------------------------------------------------- */
import { string, boolean, number } from 'yup'
import { INPUT_TYPES } from 'client/constants'
import { stringToBoolean } from 'client/models/Helper'
const getTypeProp = (type) => {
switch (type) {
@ -71,8 +72,14 @@ const getValidation = (type, mandatory, defaultValue = undefined) => {
.default(() => defaultValue)
case 'boolean':
return isMandatory
? boolean().yesOrNo().required()
: boolean().yesOrNo().notRequired()
? boolean()
.yesOrNo()
.required()
.default(() => stringToBoolean(defaultValue))
: boolean()
.yesOrNo()
.notRequired()
.default(() => stringToBoolean(defaultValue))
default:
return isMandatory
? string()

View File

@ -326,7 +326,7 @@ export const schemaUserInput = ({
}
case USER_INPUT_TYPES.boolean:
return {
type: INPUT_TYPES.CHECKBOX,
type: INPUT_TYPES.SWITCH,
validation: boolean()
.concat(requiredSchema(mandatory, boolean()))
.default(() => stringToBoolean(defaultValue))