Max Chars for Text Attributes

Contrib type: 
Module
Status: 
Uploaded for testing
Moderation: 
Not ready for moderation

Downloads

Compatibility: 
Ubercart 1.x

This module allows you to specify a maximum amount of characters that a text attribute can have. One example is if you are selling jerseys and want to limit the name on the back to 15 characters and the number to 2.

Also has support for defining that an attribute must be numeric.

The size of the attribute textfield will default to size="(max chars + 1)" but can also be configured to be set to a certain amount of pixels * max chars.

This will probably not be ported to D6, because I believe Validations API can add this functionality, albeit with a bit more overhead and complexity in config.


PreviewAttachmentSize
uc_attribute_length.zip3.24 KB
TSE
TSE's picture
Offline
Joined: 11/18/2008
Juice: 16
Works fine

Many thanx for this module, i needed a way to reduce atributes to numeric values and its works perfectly.

Greetz TSE

Bartezz's picture
Offline
Joined: 04/18/2008
Juice: 104
Re: Works fine

The code on line #62 of uc_attribute_length.module

variable_set('uc_aac_attribute_reprice', $form_values['uc_attribute_length_pixels']);

will overwrite Ubercart Ajax Attribute Calculations module's variable. (uc_aac => Ajax Attribute Calculations => get it?!?)

Commenting out the whole submit handler seems to do no harm to atrribute length module but does fix this bug!

/**
* Submit handler for uc_attribute_length width setting.
*/
//function uc_attribute_length_settings_submit($form_id, $form_values) {
//  variable_set('uc_attribute_length_pixels', $form_values['uc_attribute_length_pixels']);
//}

Cheers

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
Re: Re: Works fine

Thanks Bartezz, that is some random cruft that needs fixed. You rightfully identified that the line should be...

<?php
  variable_set
('uc_attribute_length_pixels', $form_values['uc_attribute_length_pixels']);
?>

Commenting that out is fine unless you actually want to use that setting which allows you to set the length based on pixels instead of just using size='x' for attributes of restricted length.

uberguy's picture
Offline
Joined: 02/24/2009
Juice: 22
Thanks, great module!

Hi, I like to thank for this great module. I tested on ubercart 1.x. Any plan to port it to 2.x anytime soon?

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
Re: Thanks, great module!

I'll probably move it over to d.o and put up a drupal 6 version soon.

uberguy's picture
Offline
Joined: 02/24/2009
Juice: 22
Re: Re: Thanks, great module!

Thanks. Can't wait to test this in D6.

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
@uberguy: Can Validations

@uberguy: Can Validations API work to add validation to attributes?

uberguy's picture
Offline
Joined: 02/24/2009
Juice: 22
hi cYu, I have tested out

hi cYu,

I have tested out the Validation API (thanks for info).
The validation part is working fine, but I have a problem with the HTML text field which looks like this:

input type="text" maxlength="128" name="attributes[6]" id="edit-attributes-6" size="60" value="1" class="form-text required"

The problem is the field show up too long, if say my text is 4 digits, I would like to have maxlength=4 and size=4, your module has done this perfectly.

So I try to use hook_form_alter() to change the maxlength and size as follow, but it doesn't work, the form id is correct as it has printed out.

/**
* Implementation of hook_form_alter()
*/
function my_module_form_alter(&$form, $form_state, $form_id) {

if ($form_id == "uc_product_add_to_cart_form_23") {

print $form_id;
$form['attributes[6]']['#size'] = 4;
}

}

Any ideas? I am not very good at php.

Thks.

cYu
cYu's picture
Offline
Bug FinderGetting busy with the Ubercode.
Joined: 11/19/2007
Juice: 852
re: Text Field Size
<?php
$form
['attributes[6]']['#size'] = 4;
?>

isn't going to work.

Do a print_r($form) or dsm($form) if you have devel installed locally and you will see the internals of that array in order to drill down to where that text field has it's size set.

uberguy's picture
Offline
Joined: 02/24/2009
Juice: 22
re: Text Field Size

I have done the print_r($form), but still couldn't get that attribute field, not sure anyone have done this in D6???
This is a field that I have added via /admin/store/attributes/add

Thks anyway