Skip to content
Snippets Groups Projects
Commit d3ed6724 authored by Angie Byron's avatar Angie Byron
Browse files

Issue #1149188 by fago: Fixed machine_name.js does not respect maxlength of target field.

parent 82419788
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -35,6 +35,8 @@ Drupal.behaviors.machineName = { ...@@ -35,6 +35,8 @@ Drupal.behaviors.machineName = {
if ($target.hasClass('error')) { if ($target.hasClass('error')) {
return; return;
} }
// Figure out the maximum length for the machine name.
options.maxlength = $target.attr('maxlength');
// Hide the form item container of the machine name form element. // Hide the form item container of the machine name form element.
$wrapper.hide(); $wrapper.hide();
// Determine the initial machine name value. Unless the machine name form // Determine the initial machine name value. Unless the machine name form
...@@ -103,13 +105,14 @@ Drupal.behaviors.machineName = { ...@@ -103,13 +105,14 @@ Drupal.behaviors.machineName = {
* disallowed characters in the machine name; e.g., '[^a-z0-9]+'. * disallowed characters in the machine name; e.g., '[^a-z0-9]+'.
* - replace: A character to replace disallowed characters with; e.g., '_' * - replace: A character to replace disallowed characters with; e.g., '_'
* or '-'. * or '-'.
* - maxlength: The maximum length of the machine name.
* *
* @return * @return
* The transliterated source string. * The transliterated source string.
*/ */
transliterate: function (source, settings) { transliterate: function (source, settings) {
var rx = new RegExp(settings.replace_pattern, 'g'); var rx = new RegExp(settings.replace_pattern, 'g');
return source.toLowerCase().replace(rx, settings.replace); return source.toLowerCase().replace(rx, settings.replace).substr(0, settings.maxlength);
} }
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment