Support Forum

Every time that you post a problem, PLEASE add the Joomla and the extension's versions and revisions (for example: Joomla 3.3.6, Contact Enhanced 3.3.5), PHP version and Server's Operating System. If you only manage only one site it is easier if you edit your profile and just add that information to your signature. Don't forget to add a detailed description of the problem. If possible, write down all steps to simulate the problem.

Before submitting a new post, PLEASE make sure you are running the latest version, test in different browsers (IE, FF, Chrome,..) and clear Joomla and browser's cache after every change you make.

Also, most questions are already answered in our FAQ and in iFAQ and Contact Enhanced documentation pages.

× Contact Enhanced is a contact component manager created to replace Joomla! core contacts component and add lots of advantages and new features (see Features ) and it offers many plugins and modules for several different purposes,
Product page | Documentation Page

Javascript Samples to be used with the CSS Custom field

9 years 5 months ago #12140 by douglas
Greetings,

From time to time people ask me how to create Javascript behavior to Custom Fields; I've recently added the JS Custom Field in Contact Enhanced in order to make it easier to inject JS code in the form;
JS Custom Field: ideal.fok.com.br/joomla-extens...tom-fields/106-javascript.html

I'll update this thread every time I create a new script. Please feel free to add your script here as well;

In Contact Enhanced for Joomla 2.5+ there is an option in the Multitext custom field to limit the number of characters; I've not added this feature in Contact Enhanced for Joomla 1.5 due to a limitation in the Validation script used there. However you can add a similar behavior by adding the script below to the JS Custom Field. This script requires MooTools upgrade plugin enabled;
window.addEvent('domready', function(){
	// Configuration
	var maxlen	= 300; // Number of characters allowed
	var fieldID	= 'cf_50'; // Custom Field ID: In this case the Custom Field ID is 50 
	var charsLeftMsg= ' characters left'; // Characters Left Message
	// Configuration ends;
 
	var field	= $(fieldID);
	// Inject new HTML;
	var charsLeft	= new Element('div', {id: fieldID+'-chars-left'});
	var charsLeftBox= new Element('span', {id: fieldID+'-chars-left-field'});
	var charsLeftTxt= new Element('span', {id: fieldID+'-chars-left-txt'});
	charsLeftBox.inject(charsLeft);
	charsLeftTxt.inject(charsLeftBox,'after');
	charsLeftTxt.set('text',charsLeftMsg);
	charsLeftBox.set('text',maxlen);
	charsLeft.inject(field,'after');
	// Add behaviour to field
	field.addEvent('keyup', function(e) {
		new Event(e).stop();
		var fieldValue		= field.get('value');
		fieldValue		= fieldValue.substring(0, maxlen);
		field.set('value', fieldValue);
		var fieldLength = fieldValue.length;
		charsLeftBox.set('text', (maxlen - fieldLength) );
	});
});

All the best,

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum

Copyright © 2018 IdealExtensions.com. All Rights Reserved.

This site is not affiliated with or endorsed by the Joomla!™ Project. It is not supported or warranted by the Joomla!™ Project or Open Source Matters™. The Joomla!™ logo is used under a limited license granted by Open Source Matters™, the trademark holder in the United States and other countries.
We may collect your IP address and your browser's User Agent string while using our site for security reasons and deriving aggregate information (analytics). This information is retained for a minimum of 1 and a maximum of 24 months.
Feedback