-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4519 from magento-engcom/2.3-develop-fast-lane-prs
[Magento Community Engineering] Community Contributions - 2.3-develop expedited
- Loading branch information
Showing
9 changed files
with
313 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
app/code/Magento/Checkout/view/frontend/web/js/model/billing-address-postcode-validator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
define([ | ||
'jquery', | ||
'Magento_Checkout/js/model/postcode-validator', | ||
'mage/translate', | ||
'uiRegistry' | ||
], function ( | ||
$, | ||
postcodeValidator, | ||
$t, | ||
uiRegistry | ||
) { | ||
'use strict'; | ||
|
||
var postcodeElementName = 'postcode'; | ||
|
||
return { | ||
validateZipCodeTimeout: 0, | ||
validateDelay: 2000, | ||
|
||
/** | ||
* Perform postponed binding for fieldset elements | ||
* | ||
* @param {String} formPath | ||
*/ | ||
initFields: function (formPath) { | ||
var self = this; | ||
|
||
uiRegistry.async(formPath + '.' + postcodeElementName)(self.bindHandler.bind(self)); | ||
}, | ||
|
||
/** | ||
* @param {Object} element | ||
* @param {Number} delay | ||
*/ | ||
bindHandler: function (element, delay) { | ||
var self = this; | ||
|
||
delay = typeof delay === 'undefined' ? self.validateDelay : delay; | ||
|
||
element.on('value', function () { | ||
clearTimeout(self.validateZipCodeTimeout); | ||
self.validateZipCodeTimeout = setTimeout(function () { | ||
self.postcodeValidation(element); | ||
}, delay); | ||
}); | ||
}, | ||
|
||
/** | ||
* @param {Object} postcodeElement | ||
* @return {*} | ||
*/ | ||
postcodeValidation: function (postcodeElement) { | ||
var countryId = $('select[name="country_id"]:visible').val(), | ||
validationResult, | ||
warnMessage; | ||
|
||
if (postcodeElement == null || postcodeElement.value() == null) { | ||
return true; | ||
} | ||
|
||
postcodeElement.warn(null); | ||
validationResult = postcodeValidator.validate(postcodeElement.value(), countryId); | ||
|
||
if (!validationResult) { | ||
warnMessage = $t('Provided Zip/Postal Code seems to be invalid.'); | ||
|
||
if (postcodeValidator.validatedPostCodeExample.length) { | ||
warnMessage += $t(' Example: ') + postcodeValidator.validatedPostCodeExample.join('; ') + '. '; | ||
} | ||
warnMessage += $t('If you believe it is the right one you can ignore this notice.'); | ||
postcodeElement.warn(warnMessage); | ||
} | ||
|
||
return validationResult; | ||
} | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.