Hello everyone,
I have seen many post asking about how to limit item title and description to a specified number of characters,
Many of the other answers suggested modification of core files-
But in this tutorial I will explain how to achieve this
without modifying any core files.Also i have seen many requests for item counter so users have idea of how many characters they have left...
So here it is
In this tutorial I will explain how to make An item characters counter and how to limit the number of characters allowed in bender theme - but it should be similar in most of the other themes.
First open the file item-post.php in your theme folder
To add the counter to the title - find this code<div class="control-group">
<label class="control-label" for="title[<?php echo osc_locale_code(); ?>]"><?php _e('Title', 'bender'); ?></label>
<div class="controls">
<?php ItemForm::title_input('title',osc_locale_code(), osc_esc_html( bender_item_title() )); ?>
</div>
</div>
And replace it with this Code
<div class="control-group">
<label class="control-label" for="title[<?php echo osc_locale_code(); ?>]"><?php _e('Title', 'bender'); ?></label>
<div class="controls">
<?php ItemForm::title_input('title',osc_locale_code(), osc_esc_html( bender_item_title() )); ?>
Counter: <span id="char2"></span>
<script type="text/javascript">
var title_Limit = 25;
$('#title<?php echo osc_locale_code()?>').keyup(function() {
if ($(this).val().length > title_Limit) {
$(this).val($(this).val().substr(0, title_Limit));
}
$('#char2').text(this.value.replace(/{.*}/g, '').length);
});
</script>
</div>
</div>
And then change the value "25" to the characters limit that you want!---------------------------------------------------------------------------------------------------------------------
Next we will add the counter and the limit to the description box- Find this code<div class="control-group">
<label class="control-label" for="description[<?php echo osc_locale_code(); ?>]"><?php _e('Description', 'bender'); ?></label>
<div class="controls">
<?php ItemForm::description_textarea('description',osc_locale_code(), osc_esc_html( bender_item_description() )); ?>
</div>
</div>
And replace it with this one <div class="control-group">
<label class="control-label" for="description[<?php echo osc_locale_code(); ?>]"><?php _e('Description', 'bender'); ?></label>
<div class="controls">
<?php ItemForm::description_textarea('description',osc_locale_code(), osc_esc_html( bender_item_description() )); ?>
Counter: <span id="charCount"></span>
<script type="text/javascript">
var description_Limit = 60;
$('#description<?php echo osc_locale_code()?>').keyup(function() {
if ($(this).val().length > description_Limit) {
$(this).val($(this).val().substr(0, description_Limit));
}
$('#charCount').text(this.value.replace(/{.*}/g, '').length);
});
</script>
</div>
</div>
And then change the value "60" to the characters limit that you want for description!-------------------------------------------------------------------------------------------------------------------
P.S. Your limit from the admin panel should be equal or higher than the limit you set for the counter - for example if you want to make title limit to 25 characters be sure that u set it to 25 or more in admin panel (30,35... all will work) so you avoid getting error when publishing the ad.Here you got it
Hope you enjoyed this tutorial...
If you want to know how to enable numbers only in price field check our other tutorial
http://forums.osclass.org/tips-and-tricks/%28tutorial%29-allow-numbers-only-in-price-field/Regards,
ibthemes.com