: 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,
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".
More posts by @Pierce454
4 Comments
Sorted by latest first Latest Oldest Best
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;"> 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>
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
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.
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
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.