I have a CFgrid that was working fine in CF 9.0, but now we have upgraded to 9.0.1, nothing comes up form (form.#GridName#.#Column1Name#) after the form is submitted. I made up some test code (below) which i have tried on a 9.0.1 server, which comes up with empty string in the form, were as on a 9.0 it somes up with all the info for the selected row. Any ideas on what the problem is and any fixes for it?
Cheers in advance
DUMP form: <cfdump var="#form#"><br>
<cfform action="#CGI.script_name#" method="post">
<cfset args = structNew()>
<cfset args.name = "requestGrid">
<cfset args.format = "html">
<cfset args.stripeRows = true>
<cfset args.selectmode = "row">
<cfset args.height = "150">
<cfset arg.width = "320">
<cfset args.autowidth = "yes">
<cfset args.gridLines = "yes">
<cfgrid attributeCollection="#args#">
<cfgridcolumn name="iRequestProductID" display="false">
<cfgridcolumn name="iItemID" display="false">
<cfgridcolumn name="iProductID" display="false">
<cfgridcolumn name="productName" header="Requested Product" width="150" >
<cfgridcolumn name="ItemName" header="Allocated Item" width="100" dataAlign="center">
<cfgridcolumn name="sSerialNo" header="Serial no" width="100" dataAlign="center">
<cfgridrow data = "1,1,2,test1,aaa,123">
<cfgridrow data = "1,2,2,test2,bbb,234">
<cfgridrow data = "1,3,2,test3,ccc,345">
<cfgridrow data = "1,4,2,test4,ddd,456">
<cfgridrow data = "1,5,2,test5,eee,567">
</cfgrid>
<input type="Submit" name="allocate" value="Allocate Item" style="color:ff0000" />
</cfform>
One of the enhancements in ColdFusion 9.0.1:
In ColdFusion 9, data for the first row is available on form submission in a form with dynamic grid. In ColdFusion 9.0.1, the data is not available.
Reference: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-7baf.html
Related
Currently we have ColdFusion 2016 Update 1 installed on our deployed server. After we upgraded our CF version from 9 to 2016, all cfgrids combobx columns started behaving a bit strange. Grid combobox columns are not displaying the exact values defined in cfgridcolumn values and valuesdisplay list. We have some links on the grid that opens up a pop-up with cfgrid. This grid combobox list data is getting mapped to the parent grid combobox list.
For ex: If the parent grid second column is a combobox and values="true,false" and the pop-up grid second column combobox values="FE,TSE,TS", If I try to edit pop-up grid second column, true/false is appearing in the combobox list.
Strangely this is happening with all the grids that have editable combobox columns. Can anyone please help me with this issue?
Grids settings is something like:
<cfset gridArgs = structNew()>
<cfset gridArgs.name = "LoansGrid">
<cfset gridArgs.pageSize = 20>
<cfset gridArgs.format = "html">
<cfif SERVER.ColdFusion.ProductVersion lt 9>
<cfset gridArgs.width = "99%">
</cfif>
<cfset gridArgs.autowidth = "no">
<cfset gridArgs.bindOnLoad = "true">
<cfset gridArgs.bind = "cfc:XXX.MVP.components.Manager.getRecords({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection},{Filter})">
<cfset gridArgs.stripeRows = true>
<cfset gridArgs.selectColor = "##D9E8FB">
<cfset gridArgs.selectmode = "edit">
<cfset gridArgs.onchange = "cfc:XXX.MVP.components.Manager.editRecord({cfgridaction},{cfgridrow},{cfgridchanged})">
<style>
td div, table div, form div { margin:0; } .x-grid-header { margin:0; } .x-grid-hd-row td { line-height:normal; }
</style>
<cfform name="EEEForm">
<cfinput type="hidden" name="Filter" value="#id#">
<cfgrid attributeCollection="#gridArgs#">
<cfgridcolumn name='Links' header='Links' display="true" width="170" select="no">
<cfgridcolumn name='Record_ID' header='Record ID' display="false" select="no">
<cfgridcolumn name="ID" header="ID" display="false" select="no">
<cfgridcolumn name="Number" header="Number" display="true" bold="yes">
<cfgridcolumn name="IncludeInRun" header="Include in Run" display="true" values="1,0" valuesdisplay="True,False">
<cfgridcolumn name="Status" header="Status" display="true">
<cfgridcolumn name="LastName" header="Last Name" display="true">
<cfgridcolumn name="ProductType" header="Product Type" display="true" values="#productType#" valuesdisplay="#productType#">
<cfgridcolumn name="PropertyType" header="Property Type" display="true" values="#propertyType#" valuesdisplay="#propertyType#">
........
</cfgrid>
</cfform>
I have a report which has the date selection as show below. When the report is first loaded it will show the data for the current month ie in this case from {ts '2014-06-01 00:00:00'} to {ts '2014-07-01 00:00:00'};range in all the queries on the page. When I select a date from the dropdown and submit the page, the queries still take the start and end date as 6/1 to 7/1 instead of the selected month. I tried debugging it but still not able to get it to work. Any suggestions here?
I have updated My form is like below. I want the first radio button to be selected on the first page load, I am just making the other selection empty on click of the radio button. Is there a way to save what is in the selection and just display results for the criteria selected?please suggest
<script>
function makeChoice() {
var obj1 = document.getElementById('month_dt')
var obj2 = document.getElementById('start_date')
var obj3 = document.getElementById('end_date')
if (document.getElementById('but1').checked) {
obj2.value = '';
obj3.value = '';
}
else if (document.getElementById('but2').checked) {
obj1.value = '';
}
}
</script>
<form name="month_year" method="get">
<div>
<table>
<tr>
<th align="right">
<input type="radio" name="datesel" value="1" id="but1" onClick="return makeChoice();"/>
Month/Year:</th>
<td align="left">
<select name="month_dt" id="month_dt">
<option value="">---Select one---</option>
<cfloop from="0" to="#diff_month_cnt#" index="ii">
<cfset temp_dt = dateAdd("m", -1 * ii, today) />
<cfset temp_dt = createDate(year(temp_dt), month(temp_dt), 1) />
<cfset isselected = "" />
<cfif temp_dt EQ the_month_dt>
<cfset isselected = "selected" />
</cfif>
<option value="#dateFormat(temp_dt, 'mm/dd/yyyy')#" #isselected#>#dateFormat(temp_dt, "mmmm yyyy")#</option>
</cfloop>
</select>
</td>
</tr>
<tr><td colspan="2" align="center"><em>- or -</em></td></tr>
<tr>
<th align="right"> <input type="radio" name="datesel" value="2" id="but2" onClick="return makeChoice();"/>Start Date:</th>
<td>
<input id="start_date" type="text" name="start_date" <cfif isdate(url.start_Date)>value="#dateFormat(url.start_date, 'mm/dd/yyyy')#"</cfif> size="10" maxlength="10" autocomplete="off" />
</td>
</tr>
<tr>
<th align="right">End Date:</th>
<td>
<input id="end_date" type="text" name="end_date" <cfif isdate(url.end_Date)>value="#dateFormat(url.end_date, 'mm/dd/yyyy')#"</cfif> size="10" maxlength="10" autocomplete="off" />
</td>
</tr>
<input type="submit" value=" OK " />
<cfif isDate(url.month_dt) and url.datesel eq 1>
<cfset begin_dt = createDate(year(month_dt), month(month_dt), 1) />
<cfset end_dt = dateAdd("m", 1, begin_dt) />
<cfelseif isDate(url.start_date) AND isDate(url.end_date) and url.datesel eq 2 >
<cfset begin_dt = url.start_date />
<cfset end_dt = url.end_date />
</cfif>
<cfset the_month_dt = createDate(year(begin_dt), month(begin_dt), 1) />
In the queries like
1) WHERE q.quizdate >= <cfqueryparam cfsqltype="CF_SQL_DATE" value="#the_month_dt#" />
AND q.quizdate < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#dateAdd('m', 1, the_month_dt)#" />
2) WHERE r.create_dt >= <cfqueryparam cfsqltype="CF_SQL_DATE" value="#begin_dt#" />
AND r.create_dt < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#end_dt#" />
You need to change the following code:
<cfif isDate(url.month_dt)>
<cfset begin_dt = createDate(year(month_dt), month(month_dt), 1) />
</cfif>
<cfif isDate(url.start_date)>
<cfset begin_dt = url.start_date />
</cfif>
<cfset end_dt = dateAdd("m", 1, begin_dt) />
<cfif isDate(url.end_date)>
<cfset end_dt = url.end_date />
</cfif>
to be:
<cfif isDate(url.month_dt)>
<cfset begin_dt = createDate(year(month_dt), month(month_dt), 1) />
<cfset end_dt = dateAdd("m", 1, begin_dt) />
<cfelseif isDate(url.start_date) AND isDate(url.end_date)>
<cfset begin_dt = url.start_date />
<cfset end_dt = url.end_date />
</cfif>
Use DaysInMonth to look for the last date in month. As more info is given in the question, my answer is modified a bit. You need to disable and clear the values in Start/End form fields when a user chooses to select by month and vice versa. Otherwise, the users might get confused. Place the code before the form to get the start/end dates selected by a user. The final start/end dates are begin_dt and end_dt
<cfset thisMonth = createDate(year(now()), month(now()), 1) />
<cfparam name="url.month_dt" default="" />
<cfparam name="url.start_date" default="" />
<cfparam name="url.end_date" default="" />
<cfparam name="bRadioMonth" default="" />
<cfparam name="bRadioStartEnd" default="" />
<cfif len(url.month_dt) AND isDate(url.month_dt)>
<cfset begin_dt = createDate(year(url.month_dt), month(url.month_dt), 1) />
<cfset end_dt = createDate(year(begin_dt), month(begin_dt), DaysInMonth(begin_dt)) />
<!--- Disable form fields start_date and end_date --->
<cfset bFieldMonth = "">
<cfset bFieldStartEnd = "disabled">
<cfset bRadioMonth = "checked">
<cfelseif len(url.start_date) AND len(url.end_date)
AND isDate(url.start_date) AND isDate(url.end_date)>
<cfset begin_dt = createDate(year(url.start_date), month(url.start_date), day(url.start_date)) />
<cfset end_dt = createDate(year(url.end_date), month(url.end_date), day(url.end_date)) />
<!--- Disable form field month_dt --->
<cfset bFieldMonth = "disabled">
<cfset bFieldStartEnd = "">
<cfset bRadioStartEnd = "checked">
<cfelse>
<cfset begin_dt = thisMonth />
<cfset end_dt = createDate(year(begin_dt), month(begin_dt), DaysInMonth(begin_dt)) />
<!--- Default to disable form fields start_date and end_date --->
<cfset bFieldMonth = "">
<cfset bFieldStartEnd = "disabled">
<cfset bRadioMonth = "checked">
</cfif>
javascript:
<script>
function makeChoice() {
var fieldMonth = document.getElementById('month_dt');
var fieldStart = document.getElementById('start_date');
var fieldEnd = document.getElementById('end_date');
if (document.getElementById('but1').checked) {
fieldMonth.disabled = false;
fieldStart.disabled = true;
fieldEnd.disabled = true;
fieldStart.value = '';
fieldEnd.value = '';
}
else if (document.getElementById('but2').checked) {
fieldMonth.options[0].selected = true;
fieldMonth.disabled = true;
fieldStart.disabled = false;
fieldEnd.disabled = false;
}
}
</script>
If form is submitted, return selected start/end dates and run query:
<cfoutput>
Selected Start Date: #dateFormat(begin_dt, 'mm/dd/yyyy')# End Date: #dateFormat(end_dt, 'mm/dd/yyyy')#
</cfoutput>
<cfif isdefined("form.submit")>
<!---
Run Query.
1) WHERE q.quizdate >= <cfqueryparam cfsqltype="CF_SQL_DATE" value="#begin_dt#" />
AND q.quizdate < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#DATEADD('d',1,end_dt)#" />
2) WHERE r.create_dt >= <cfqueryparam cfsqltype="CF_SQL_DATE" value="#begin_dt#" />
AND r.create_dt < <cfqueryparam cfsqltype="CF_SQL_DATE" value="#DATEADD('d',1,end_dt)#" />
--->
</cfif>
I have a cfform with multiple fields and I'm using an onpage post method to post information gathered from the user's entries into a session to pass onto each page of the registration process.
What I cannot figure out for the life of me and this is probably something simple is that if I have hard coded options for a how can I pass what is selected into the session? I can get a session.house.main.form.saletype is undefined error when trying to display the value selected on the next page. All my other form fields show up fine.
I removed all the other form fields to make it easier to check my code:
<cfif not structKeyExists(session.house, "main")>
<cfset session.house.main= {saletype="",
name=""}>
</cfif>
<cfparam name="form.saletype" default="#session.house.main.saletype#">
<cfparam name="form.name" default="#session.house.main.name#">
<cfif structKeyExists(form, "submit")>
<cfset session.house.main = {saletype=form.saletype,
name=form.name}>
<cflocation url="page2.cfm" addtoken="false" />
</cfif>
<cfform method="post">
<cfselect name="saletype" size="1">
<option value="Lease" selected>Lease</option>
<option value="Rent Now">Rent Now</option>
</cfselect><br />
<cfinput type="text" name="name" id="name" value="#form.name#" required="yes" message="Please enter your name"><br />
<cfinput type="submit" name="submit" id="submit" value="Save"><br />
</cfform>
Edit: Fixed cfselect name. How would I set the form.saletype into the cfselect with two hardcoded options?
I tried to bind a CFGrid in ColdFusion through a CFC function which works correctly, but after login when I tried to surf to the page the CFGrid does not get populated with any records.
Here is my grid.cfm code:
<cfform name="GridForm">
<cfgrid format="html" name="UserGrid" pagesize="10" selectmode="row" bind="cfc:Consumer.getUserinfo({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})">
<cfgridcolumn name="FirstName" width="300" header="FirstName" />
<cfgridcolumn name="LastName" width="180" header="LastName" />
<cfgridcolumn name="UserName" width="120" header="UserName" />
<cfgridcolumn name="Age" width="60" header="Age" />
</cfgrid>
<br/>
</cfform>
And here is my cfc function:
<cfcomponent output="false">
<cffunction name="getUserInfo" access="remote" returntype="struct" >
<cfargument name="page" required="true" />
<cfargument name="pageSize" required="true" />
<cfargument name="gridsortcolumn" required="true" />
<cfargument name="gridsortdirection" required="true" />
<cfif arguments.gridsortcolumn eq "">
<cfset arguments.gridsortcolumn = "FirstName" />
<cfset arguments.gridsortdirection = "asc" />
</cfif>
<cfquery name="GetUser" datasource="MyDatabase" >
select *
from UserInfo
order by #arguments.gridsortcolumn# #arguments.gridsortdirection#
</cfquery>
<cfreturn queryconvertforgrid(GetUser, page, pagesize) />
</cffunction>
</cfcomponent>
Why doesn't this grid get populated after the login?
I recommend using the developer tools / javascript console in Chrome. Turn on log XMLHTTPRequests. Then, next time you reload your app, the console will show you all of the ajax calls your app is making and if they succeed or fail.
If you have a failing request you can right click on it and open it in a new tab to see the error details just like you would normally trouble shoot a problem.
I have a checkbox inside of a form tag and I basically want to persist the checked state of the checkbox using a session. Apparently I'm doing it wrong because whenever I reload the page it sets the session back to off(which is the default value for the checkbox param). Here is the code i'm using.
Form:
<cfform name="matureContent" method="post" action="/index.cfm?fuseaction=main.Channels_Detail&c=#URL.c#" enctype="multipart/form-data">
<cfif SESSION.matureSession eq "on">
<input name="myCheckbox" type="checkbox" checked="checked" />
<cfelse>
<input name="myCheckbox" type="checkbox"/>
</cfif>
<input type="submit" value="Save" />
</cfform>
Session variable and params if they are not present on page load.
<cfparam name="form.myCheckbox" default="off">
<cfparam name="SESSION.maturesession" default="off">
<cfset SESSION.maturesession = form.myCheckbox>
If i'm going about this completely the wrong way let me know. Thanks.
<cfparam name="form.myCheckbox"
default="off">
<cfparam name="SESSION.maturesession"
default="off">
<cfset SESSION.maturesession =
form.myCheckbox>
I think that will result in overwriting the saved value if you return to the page from somewhere else. Instead, try updating the session value only when the form was submitted. Also, since you are using a cfform you could shortcut things by using yes/no instead of on/off.
Update I forgot the cfparam for the session variable. But if you truly want to carry it throughout the session, you could also initialize it onSessionStart instead.
<cfparam name="SESSION.maturesession" default="no">
<cfif structKeyExists(FORM, "submit")>
<cfparam name="form.myCheckbox" default="no">
<cfset SESSION.maturesession = form.myCheckbox>
</cfif>
<cfform name="test" method="post" ....>
<cfinput name="myCheckbox" type="checkbox" value="yes" checked="#session.matureSession#" />
<input type="submit" name="submit" value="Save" />
</cfform>
Do you actually have sessions turned on?
You have to explicitly turn on sessions for your app using the CFAPPLICATION tag if you're using Application.cfm, or, if you're using Application.cfc, by setting this.sessionManagement = true.
Application.cfm:
<cfapplication
name = "application name"
applicationTimeout = #CreateTimeSpan(0,2,0,0)#
sessionManagement = "yes"
sessionTimeout = #CreateTimeSpan(0,0,20,0)#>
Application.cfc:
<cfcomponent output="false">
<!--- Application name, should be unique --->
<cfset this.name = "ApplicationName">
<!--- How long application vars persist --->
<cfset this.applicationTimeout = createTimeSpan(0,2,0,0)>
<!--- Should we even use sessions? --->
<cfset this.sessionManagement = true>
<!--- How long do session vars persist? --->
<cfset this.sessionTimeout = createTimeSpan(0,0,20,0)>
</cfcomponent>
OK, then if sessions ARE turned on, when you submit the form, what does the code look like that you're posting the form to?