Pregunta
Dynamically creating a CF Tag
Greetings,
I would like to dynamically determine what attributes are present in a ColdFusion tag. I have done the following to test the theory:
<cfset inputAttr['name'] = "tControlName">
<cfset inputAttr.label = "Control Label">
<cfset inputAttr.value = "Some string value">
<cfset inputAttr.type = "text">
<cfform name="fTest" method="post" action="">
<cfset tagAttr = "<cfinput ">
<cfloop collection=#inputAttr# item="attr">
<cfset tagAttr = '#tagAttr# #attr#="#inputAttr[attr]#"'>
</cfloop>
<cfset tagAttr = "#tagAttr# >">
<cfoutput>#tagAttr#</cfoutput>
</cfform>
If I look at the source for the page it is correct, but no input is creates. If however I change it to "<input" instead of <cfinput" it works fine. Unfortunately I would like to use attributes like validate that are only available in <cfinput>.
I assume that the stuff within the <cfoutput> tags are bding sent directly to the browser and bypassing the processing be CF. So I have tried leaving out the "<cfinput " and ">" from the tagAttr and using the following:
<cfinput "#tagAttr#" >
in a variety of forms but keep getting an error of one sort or another.
Am I missing something or is this not possible?
Thanks for your help.
I would like to dynamically determine what attributes are present in a ColdFusion tag. I have done the following to test the theory:
<cfset inputAttr['name'] = "tControlName">
<cfset inputAttr.label = "Control Label">
<cfset inputAttr.value = "Some string value">
<cfset inputAttr.type = "text">
<cfform name="fTest" method="post" action="">
<cfset tagAttr = "<cfinput ">
<cfloop collection=#inputAttr# item="attr">
<cfset tagAttr = '#tagAttr# #attr#="#inputAttr[attr]#"'>
</cfloop>
<cfset tagAttr = "#tagAttr# >">
<cfoutput>#tagAttr#</cfoutput>
</cfform>
If I look at the source for the page it is correct, but no input is creates. If however I change it to "<input" instead of <cfinput" it works fine. Unfortunately I would like to use attributes like validate that are only available in <cfinput>.
I assume that the stuff within the <cfoutput> tags are bding sent directly to the browser and bypassing the processing be CF. So I have tried leaving out the "<cfinput " and ">" from the tagAttr and using the following:
<cfinput "#tagAttr#" >
in a variety of forms but keep getting an error of one sort or another.
Am I missing something or is this not possible?
Thanks for your help.
