Quick and dirty patch to add maxlength as an option on textfields.

@@ -28,6 +28,15 @@
     '#maxlength' => 10,
     '#weight' => 0,
   );
+  $editFields['extra']['maxlength'] = array (
+    '#type' => 'textfield',
+    '#title' => t("Maxlength"),
+    '#default_value' => $currfield['extra']['maxlength'],
+    '#description' => t('Maxlength of the textfield.'),
+    '#size' => 5,
+    '#maxlength' => 10,
+    '#weight' => 1,
+  );
   $editFields['extra']['attributes']['disabled'] = array (
     '#type' => 'checkbox',
     '#title' => t("Disabled"),
@@ -61,6 +70,9 @@
   if ($component['extra']['width'] > 0) {
     $formItem['#size'] = $component['extra']['width'];
   }
+  if ($component['extra']['maxlength'] > 0) {
+    $formItem['#maxlength'] = $component['extra']['maxlength'];
+  }
   
   return $formItem;
 }

Comments

quicksketch’s picture

Status: Needs review » Needs work

Thanks Mike! Could you post the patch in the Unified format (with the -u flag)?

BioALIEN’s picture

Mikegull, +1 for this patch, it answers a feature request I posted about this. Ideally it should support minimum and maximum just like CCK module.

quicksketch, I believe this should be patched against the 5.x version then ported back to 4.7.x?
I think we need to have a clear version which contains all the latest features, in this case its the 5.x branch and the most popular of these may be ported back based on demand. I believe this will organise everything and be inline with the Drupal way of development. What's your opinion on this?

quicksketch’s picture

Yes, making a new official release wouldn't be a bad idea. Most patches like this one apply easily to 4.7 and 5 branches and I try to keep them in sync at the moment.

quicksketch’s picture

Status: Needs work » Fixed

I ended up patching by hand, please post complete patches in the future. Thanks for your contribution!

Anonymous’s picture

Status: Fixed » Closed (fixed)