Commit 1b31c7fd authored by jrockowitz's avatar jrockowitz Committed by jrockowitz

Issue #3000560 by jrockowitz, Drutech: Add an option for hashed telephon number (123XXX)

parent 149159ff
/**
* @file
* JavaScript behaviors for input hiding.
*/
(function ($, Drupal) {
'use strict';
var isChrome = /Chrome/.test(window.navigator.userAgent) && /Google Inc/.test(window.navigator.vendor);
/**
* Initialize input hiding.
*
* @type {Drupal~behavior}
*/
Drupal.behaviors.webformInputHide = {
attach: function (context) {
// Apply chrome fix to prevent password input from being autofilled.
// @see https://stackoverflow.com/questions/15738259/disabling-chrome-autofill
if (isChrome) {
$(context).find('form:has(input.js-webform-input-hide)')
.once('webform-input-hide-chrome-workaround')
.each(function () {
$(this).prepend('<input style="display:none" type="text" name="chrome_autocomplete_username"/><input style="display:none" type="password" name="chrome_autocomplete_password"/>');
});
}
// Convert text based inputs to password input on blur.
$(context).find('input.js-webform-input-hide')
.once('webform-input-hide')
.each(function() {
var type = this.type;
// Initialize input hiding.
this.type = 'password';
// Attach blur and focus event handlers.
$(this)
.on('blur', function() {
this.type = 'password';
})
.on('focus', function() {
this.type = type;
$(this).removeAttr('autocomplete');
});
});
}
};
})(jQuery, Drupal);
......@@ -409,6 +409,11 @@ elements: |
'#type': textfield
'#title': 'Form element (Input mask: Phone)'
'#input_mask': '(999) 999-9999'
form_element_input_hide:
'#type': textfield
'#title': 'Form element (Input hiding)'
'#input_hide': true
'#default_value': '{value}'
title_display_before:
'#type': textfield
'#title': 'Title displayed before'
......
......@@ -127,6 +127,20 @@ elements: |
'#type': textfield
'#title': Phone
'#input_mask': '(999) 999-9999'
input_hide_elements:
'#type': details
'#title': 'Input hiding elements'
'#open': true
textfield_input_hide:
'#type': textfield
'#title': "Textfield with input hiding"
'#input_hide': true
'#default_value': '{value}'
email_input_hide:
'#type': email
'#title': "Email with input hiding"
'#input_hide': true
'#default_value': 'example@example.com'
widget_elements:
'#type': details
'#title': 'Widget elements'
......
......@@ -21,7 +21,10 @@ class Email extends TextBase {
* {@inheritdoc}
*/
public function getDefaultProperties() {
return parent::getDefaultProperties() + $this->getDefaultMultipleProperties();
return [
'input_hide' => FALSE,
] + parent::getDefaultProperties()
+ $this->getDefaultMultipleProperties();
}
/**
......
......@@ -25,6 +25,7 @@ class Telephone extends TextBase {
*/
public function getDefaultProperties() {
return [
'input_hide' => FALSE,
'multiple' => FALSE,
'international' => FALSE,
'international_initial_country' => '',
......
......@@ -92,6 +92,12 @@ abstract class TextBase extends WebformElementBase {
$element['#attributes']['class'][] = 'js-webform-input-mask';
$element['#attached']['library'][] = 'webform/webform.element.inputmask';
}
// Input hiding.
if (!empty($element['#input_hide'])) {
$element['#attributes']['class'][] = 'js-webform-input-hide';
$element['#attached']['library'][] = 'webform/webform.element.inputhide';
}
}
/**
......@@ -132,6 +138,14 @@ abstract class TextBase extends WebformElementBase {
$form['form']['input_mask']['#access'] = FALSE;
}
// Input hiding.
$form['form']['input_hide'] = [
'#type' => 'checkbox',
'#title' => $this->t('Input hiding'),
'#description' => $this->t('Hide the input of the element when the input is not being focused.'),
'#return_value' => TRUE,
];
// Pattern.
$form['validation']['pattern'] = [
'#type' => 'webform_checkbox_value',
......
......@@ -24,6 +24,7 @@ class TextField extends TextBase {
return [
// Form display.
'input_mask' => '',
'input_hide' => FALSE,
// Form validation.
'counter_type' => '',
'counter_minimum' => '',
......
......@@ -21,7 +21,10 @@ class Url extends TextBase {
* {@inheritdoc}
*/
public function getDefaultProperties() {
return parent::getDefaultProperties() + $this->getDefaultMultipleProperties();
return [
'input_hide' => FALSE,
] + parent::getDefaultProperties()
+ $this->getDefaultMultipleProperties();
}
/**
......
......@@ -601,6 +601,14 @@ webform.element.inputmask:
- core/jquery.once
- webform/libraries.jquery.inputmask
webform.element.inputhide:
version: VERSION
js:
js/webform.element.inputhide.js: {}
dependencies:
- core/drupal
- core/jquery.once
webform.element.likert:
version: VERSION
css:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment