Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ const ValidationComponent = ( {
url: string;
color: string;
integer: number;
number: number;
boolean: boolean;
customEdit: string;
categories: string[];
Expand All @@ -542,6 +543,7 @@ const ValidationComponent = ( {
url: 'https://example.com',
color: '#ff6600',
integer: 2,
number: 3.14,
boolean: true,
categories: [ 'astronomy' ],
countries: [ 'us' ],
Expand Down Expand Up @@ -616,6 +618,13 @@ const ValidationComponent = ( {

return null;
};
const customNumberRule = ( value: ValidatedItem ) => {
if ( ! /^\d+\.\d{2}$/.test( value?.number?.toString() ) ) {
return 'Number must have exactly two decimal places.';
}

return null;
};
const customBooleanRule = ( value: ValidatedItem ) => {
if ( value.boolean !== true ) {
return 'Boolean must be active.';
Expand Down Expand Up @@ -750,6 +759,15 @@ const ValidationComponent = ( {
custom: maybeCustomRule( customIntegerRule ),
},
},
{
id: 'number',
type: 'number',
label: 'Number',
isValid: {
required,
custom: maybeCustomRule( customNumberRule ),
},
},
{
id: 'boolean',
type: 'boolean',
Expand Down Expand Up @@ -850,6 +868,7 @@ const ValidationComponent = ( {
'url',
'color',
'integer',
'number',
'boolean',
'categories',
'countries',
Expand Down
Loading