PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.4.1
JetFormBuilder — Dynamic Blocks Form Builder v3.6.4.1
3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / blocks-v2 / phone-field / assets / src / frontend / restrictions / PhoneRestriction.js
jetformbuilder / modules / blocks-v2 / phone-field / assets / src / frontend / restrictions Last commit date
PhoneRestriction.js 4 months ago
PhoneRestriction.js
69 lines
1 let {
2 AdvancedRestriction,
3 Restriction,
4 } = window.JetFormBuilderAbstract || {};
5
6 // Fallback if AdvancedRestriction is not available
7 AdvancedRestriction = AdvancedRestriction || Restriction;
8
9 /**
10 * Phone Number Validation Restriction
11 */
12 function PhoneRestriction() {
13 AdvancedRestriction.call( this );
14
15 this.type = 'phone_validation';
16 }
17
18 PhoneRestriction.prototype = Object.create( AdvancedRestriction.prototype );
19
20 /**
21 * Only apply this restriction if field is a phone field
22 */
23 PhoneRestriction.prototype.isSupported = function ( node ) {
24 const isPhoneField = node.classList.contains( 'phone-field' );
25
26 return isPhoneField;
27 };
28
29 /**
30 * Validate phone number using intl-tel-input
31 */
32 PhoneRestriction.prototype.validate = function () {
33 const input = this.reporting.input;
34 const wrapper = input.getWrapperNode();
35 const intlInput = wrapper?.querySelector('input.phone-field-intl');
36
37 // If itiInstance is not ready yet, skip validation (return true)
38 if ( ! input.itiInstance ) {
39 return true;
40 }
41
42 // If intl input field is empty, let required restriction handle it
43 if ( ! intlInput || ! intlInput.value.trim() ) {
44 return true;
45 }
46
47 // Validate using intl-tel-input
48 const isValid = input.itiInstance.isValidNumber();
49
50 return isValid;
51 };
52
53 /**
54 * Return validation error message
55 */
56 PhoneRestriction.prototype.getRawMessage = function () {
57 // Try to get custom message from field configuration
58 const customMessage = this.getMessageBySlug?.( 'phone_invalid' );
59
60 if ( customMessage ) {
61 return customMessage;
62 }
63
64 // Default message
65 return 'Please enter a valid phone number';
66 };
67
68 export default PhoneRestriction;
69