* * @param value - The value that is failing * @param validation - The validation object
( validation: FormKitValidation, removeImmediately: boolean )
| 422 | * @param validation - The validation object |
| 423 | */ |
| 424 | function createFailedMessage( |
| 425 | validation: FormKitValidation, |
| 426 | removeImmediately: boolean |
| 427 | ): void { |
| 428 | const node = validation.observer |
| 429 | if (isKilled(node)) return |
| 430 | |
| 431 | if (!validation.messageObserver) { |
| 432 | validation.messageObserver = createObserver(node._node) |
| 433 | } |
| 434 | validation.messageObserver.watch( |
| 435 | (node) => { |
| 436 | const i18nArgs: FormKitValidationI18NArgs = createI18nArgs( |
| 437 | node, |
| 438 | validation |
| 439 | ) |
| 440 | return i18nArgs |
| 441 | }, |
| 442 | (i18nArgs) => { |
| 443 | const customMessage = createCustomMessage(node, validation, i18nArgs) |
| 444 | // Here we short circuit the i18n system to force the output. |
| 445 | const message = createMessage({ |
| 446 | blocking: validation.blocking, |
| 447 | key: `rule_${validation.name}`, |
| 448 | meta: { |
| 449 | /** |
| 450 | * Use this key instead of the message root key to produce i18n validation |
| 451 | * messages. |
| 452 | */ |
| 453 | messageKey: validation.name, |
| 454 | /** |
| 455 | * For messages that were created *by or after* a debounced or async |
| 456 | * validation rule — we make note of it so we can immediately remove them |
| 457 | * as soon as the next commit happens. |
| 458 | */ |
| 459 | removeImmediately, |
| 460 | /** |
| 461 | * Determines if this message should be passed to localization. |
| 462 | */ |
| 463 | localize: !customMessage, |
| 464 | /** |
| 465 | * The arguments that will be passed to the validation rules |
| 466 | */ |
| 467 | i18nArgs, |
| 468 | }, |
| 469 | type: 'validation', |
| 470 | value: customMessage || 'This field is not valid.', |
| 471 | }) |
| 472 | node.store.set(message) |
| 473 | } |
| 474 | ) |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * Returns a custom validation message if applicable. |
no test coverage detected