Skip to content

Commit

Permalink
feat(ui): validate number item multipleOf
Browse files Browse the repository at this point in the history
  • Loading branch information
psychedelicious committed Jan 10, 2025
1 parent 204f0f3 commit 9b15289
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions invokeai/frontend/web/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,7 @@
"collectionNumberLTMin": "{{value}} < {{minimum}} (inc min)",
"collectionNumberGTExclusiveMax": "{{value}} >= {{exclusiveMaximum}} (exc max)",
"collectionNumberLTExclusiveMin": "{{value}} <= {{exclusiveMinimum}} (exc min)",
"collectionNumberNotMultipleOf": "{{value}} not multiple of {{multipleOf}}",
"noModelSelected": "No model selected",
"noT5EncoderModelSelected": "No T5 Encoder model selected for FLUX generation",
"noFLUXVAEModelSelected": "No VAE model selected for FLUX generation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const validateNumberFieldCollectionValue = (
template: IntegerFieldCollectionInputTemplate | FloatFieldCollectionInputTemplate
): string[] => {
const reasons: string[] = [];
const { minItems, maxItems, minimum, maximum, exclusiveMinimum, exclusiveMaximum } = template;
const { minItems, maxItems, minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf } = template;
const count = value.length;

// Image collections may have min or max items to validate
Expand All @@ -88,19 +88,22 @@ export const validateNumberFieldCollectionValue = (
reasons.push(t('parameters.invoke.collectionTooManyItems', { count, maxItems }));
}

for (const int of value) {
if (maximum !== undefined && int > maximum) {
for (const num of value) {
if (maximum !== undefined && num > maximum) {
reasons.push(t('parameters.invoke.collectionNumberGTMax', { value, maximum }));
}
if (minimum !== undefined && int < minimum) {
if (minimum !== undefined && num < minimum) {
reasons.push(t('parameters.invoke.collectionNumberLTMin', { value, minimum }));
}
if (exclusiveMaximum !== undefined && int >= exclusiveMaximum) {
if (exclusiveMaximum !== undefined && num >= exclusiveMaximum) {
reasons.push(t('parameters.invoke.collectionNumberGTExclusiveMax', { value, exclusiveMaximum }));
}
if (exclusiveMinimum !== undefined && int <= exclusiveMinimum) {
if (exclusiveMinimum !== undefined && num <= exclusiveMinimum) {
reasons.push(t('parameters.invoke.collectionNumberLTExclusiveMin', { value, exclusiveMinimum }));
}
if (multipleOf !== undefined && num % multipleOf !== 0) {
reasons.push(t('parameters.invoke.collectionNumberNotMultipleOf', { value, multipleOf }));
}
}

return reasons;
Expand Down

0 comments on commit 9b15289

Please sign in to comment.