Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CF Slider Custom Tag Help

Status
Not open for further replies.

firepwr

IS-IT--Management
May 22, 2006
31
0
0
US
We found this really cool slider tag for Coldfusion at the following location: [URL unfurl="true"]http://www.asfusion.com/blog/entry/cfslider-custom-tag/[/url]. The problem is that it's missing one core piece of functionality...no matter what we've tried we can't seem to pass a value to the slider and have it reflect that value (i.e. the slider is moved to the position of the value) when it loads.

Example: If we have a slider representing values from 0 to 50 the slider always starts at 0 on the far left. We would like to be able to query what the previous value was and have the slider load that way. So with the example above, if the previous value was 25, we'd expect the slider to load with the slider bar at the half way mark (not all the way on the left as it does presently).

Please note that we've already tried posting a similar request on the site and so far haven't gotten any response....

Here's a quick example if you want to see the code and tinker with it:

Name this file index.cfm:
Code:
<center><cfform name="myform" height="5000" width="600" format="Flash" timeout="1000" method="post" action="##">

<cfformgroup type="panel" label="Example">

	<cfformgroup type="horizontal">

		<cf_slider name="mySlider1" width="150" minValue="0" maxValue="60" showValues="yes" thumStyle="cornerRadius:4; borderThickness:1;">
		<cfinput width="25" value="17" name="Test_Output" type="text" bind="{mySlider1.text}" readonly="yes"/>
		<cfformitem type="text" >Hours</cfformitem>

	</cfformgroup>

	<cfformgroup type="horizontal" style="horizontalAlign:center;">
  		<cfinput type="submit" name="btnSubmit" value="Submit">
	</cfformgroup>

</cfformgroup>

</cfform></center>

Name this file slider.cfm:
Code:
<cfparam name="attributes.name" default="slider">
<cfparam name="attributes.minValue" default="0">
<cfparam name="attributes.maxValue" default="10">
<cfparam name="attributes.showValues" default="true">
<cfparam name="attributes.width" default="">
<cfparam name="attributes.thumStyle" default="">
<cfparam name="attributes.onChange" default="">

<cfsavecontent variable="#attributes.name#_mDown">
	<cfoutput>
	var hr = #attributes.name#;
	var thum = #attributes.name#_thum;
	var leftLabel = #attributes.name#_leftLabel;
	var rightLabel = #attributes.name#_rightLabel;
	_root.calculatePosition = function()
	{
		thum._x
		var maxValue = Number(rightLabel.text);
		var minValue = Number(leftLabel.text);
		var totalDistance = hr.width - thum.width;
		var range =  maxValue - minValue;
		var perc =  thum._x/totalDistance*100;
		return Math.round( minValue + ( perc/100* range ) );
	}
	_root.onEnterFrame = function()
	{
		if(hr._xmouse >= 0 && hr._xmouse <= (hr.width - thum.width))
		{
			thum._x = hr._xmouse;
		}
		else if(hr._xmouse < 0 )
		{
			thum._x = 0;
		}
		else
		{
			thum._x = hr.width - (thum.width);
		}
		hr.text = _root.calculatePosition();
		hr.dispatchEvent({type:'change'})
		updateAfterEvent();
	}
	_root.onMouseUp = function()
	{
		onEnterFrame = undefined;
	}
	</cfoutput>
</cfsavecontent>

<cfformgroup type="horizontal" style="horizontalGap:2; indicatorGap:0;">
	<cfif attributes.showValues>
		<cfinput name="#attributes.name#_leftLabel" type="text" width="{#attributes.name#_leftLabel.text.length * 9 + 4}" value="#attributes.minValue#" style="borderStyle:none;  textAlign:'right';" readonly="yes"/>
	<cfelse>
		<cfinput name="#attributes.name#_leftLabel" type="text" width="0" visible="false" value="#attributes.minValue#" readonly="yes"/>
	</cfif>
		<cfformgroup type="hbox" width="#attributes.width#" style="verticalGap:-12; indicatorGap:0; ">
			<cfformitem type="spacer" height ="22" />
				<cfinput name="#attributes.name#" type="text" height="3" onChange="#attributes.onChange#" disabled="true"/>
			<cfinput type="button" value="" width="10"  name ="#attributes.name#_thum" onMouseDown="#evaluate(attributes.name&'_mDown')#" style="#attributes.thumStyle#">
		</cfformgroup>
	<cfif attributes.showValues>
		<cfinput name="#attributes.name#_rightLabel" type="text" width="{#attributes.name#_rightLabel.text.length * 9 + 4}" value="#attributes.maxValue#" style="borderStyle:none; textAlign:'left';" readonly="true" disabled="true"/>
	<cfelse>
		<cfinput name="#attributes.name#_rightLabel" type="text" width="0" visible="false" value="#attributes.maxValue#" readonly="true" disabled="true"/>
	</cfif>
</cfformgroup>

Any help or suggestions would be greatly appreciated!
 
Where's the code for the custom tag? It doesn't appear to have a start position attribute that you can set.

 
That's everything. I created index.cfm as a simple example (our real file is obviously more involved) and [tt]slider.cfm[/tt] is the custom tab that we downloaded off the site....
 
Left another comment on their website but it would appear they're not very good at supporting their tag.... It's too bad too---it could be really useful if it didn't have this huge limitation. :-(
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top