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:
parent
af05a4c991
commit
9ce5fc5fd8
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -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))
|
||||
|
Loading…
x
Reference in New Issue
Block a user