HEX
Server: LiteSpeed
System: Linux eko108.isimtescil.net 4.18.0-477.21.1.lve.1.el8.x86_64 #1 SMP Tue Sep 5 23:08:35 UTC 2023 x86_64
User: uyarreklamcomtr (11202)
PHP: 7.4.33
Disabled: opcache_get_status
Upload Files
File: /var/www/vhosts/uyarreklam.com.tr/httpdocs/get-validity-message-for-input.ts.tar
packages/woocommerce-blocks/packages/checkout/utils/validation/get-validity-message-for-input.ts000064400000002040151555765540045512 0ustar00var/www/vhosts/uyarreklam.com.tr/httpdocs/wp-content/plugins/woocommerce/**
 * External dependencies
 */
import { __, sprintf } from '@wordpress/i18n';

/**
 * Converts an input's validityState to a string to display on the frontend.
 *
 * This returns custom messages for invalid/required fields. Other error types use defaults from the browser (these
 * could be implemented in the future but are not currently used by the block checkout).
 */
const getValidityMessageForInput = (
	label: string,
	inputElement: HTMLInputElement
): string => {
	const { valid, customError, valueMissing, badInput, typeMismatch } =
		inputElement.validity;

	// No errors, or custom error - return early.
	if ( valid || customError ) {
		return inputElement.validationMessage;
	}

	const invalidFieldMessage = sprintf(
		/* translators: %s field label */
		__( 'Please enter a valid %s', 'woo-gutenberg-products-block' ),
		label.toLowerCase()
	);

	if ( valueMissing || badInput || typeMismatch ) {
		return invalidFieldMessage;
	}

	return inputElement.validationMessage || invalidFieldMessage;
};

export default getValidityMessageForInput;