Mobile app version of vmapp.org
Login or Join
Pierce454

: Limit magento title length in admin I would really like to limit the title length on products in Magento. What I've tried is adding 'maxlength' => 65 somewhere in appcodecoreMageAdminhtmlBlock,

@Pierce454

Posted in: #Google #Html #Magento #Seo

I would really like to limit the title length on products in Magento.

What I've tried is adding 'maxlength' => 65 somewhere in appcodecoreMageAdminhtmlBlock, without success.

Does someone know how to add this feature? In HTML it will just be adding length="65" maxlength="65".

10.04% popularity Vote Up Vote Down


Login to follow query

More posts by @Pierce454

4 Comments

Sorted by latest first Latest Oldest Best

 

@Sent6035632

JS or POST trunc is the best bet, but an alternate failproof method is at the DB. You can limit it in DB by changing the cell structure to varchar(65) which would only allow 65 characters to be stored there. In phpMyAdmin you find the table, click it, then look for the "structure" tab. Find the col you wanna limit, pick varchar from dropdown, then set it to 65. This will also trunc all existing titles to 65.

EDIT: This script may be helpful too if you just wanna count the chars instead and leave it to your editors to keep it around 65. This would work on any field, just change the input[name=""] to whatever field you need counted:

<script type="text/javascript">
var count_name = $('input[name="MY-TITLE-INPUT-NAME"]');
var count_name_val = $(count_name).val().length;
var stage_65 = '<br/><div style="font-style:italic;">&nbsp;&nbsp;Using <span class="stage_65">' + count_name_val + '</span> of 65 Google Chars</div>';

$(count_name).after(stage_65).on('keyup', function(){
$('.stage_65').html($(this).val().length);
});
</script>

10% popularity Vote Up Vote Down


 

@Gretchen104

Copy the app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php

to

app/code/local/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Attributes.php

In the function _prepareForm(),

after the line if ($form->getElement('meta_description')) { ...

Add

if ($form->getElement('name')) {
$form->getElement('name')->setOnkeyup('checkMaxLength(this, 1500);');
}


This should work

10% popularity Vote Up Vote Down


 

@Speyer207

As a result from that SO question. One repeating pattern in form creation is $fieldset->addField, so that presented itself as a key way to grep in files.

user@magento:~/www/app$ grep -rin "addField.*text" * | grep -i product
code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Simple.php:140: $fieldset->addField('simple_product_inventory_qty', 'text', array(


There were about a dozen results which were quickly narrowed down (we're not caring about giftcard or Attribute sets). I'm not 100% sure THIS file is the answer but it seems that some logic could be added to catch whether or not the input's name=="Name" and then a maxlength could then be added in.

10% popularity Vote Up Vote Down


 

@Candy875

After almost 10 hours of searching I gave the up the "best" way, and choose for the roundabout.

Simply add

document.getElementById("name").setAttribute("maxlength", "65");
document.getElementById("name").setAttribute("length", "65");


to app/design/adminhtml/default/default/template/catalog/wysiwyg/js.phtml

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme