Back

custom field couple with program

  • Created: Nov 15, 2013
  • Author: shimanan
  • Title: computer
  • Company: none
  • Site: none

Description

This code will pull a list of content into a custom field and create a select box for each result.it couple with  programe  code  go to interner code,see  edit_field.jsp,this code  work  well.

Code

${esc.hash}${esc.hash}${esc.hash}${esc.hash}prepare  work:

${esc.hash}${esc.hash}new strutcture: departStruct
field          field type          label
name            text  (string)     english id
label           text (string)      label
sortorder       text (int)         sort order

${esc.hash}${esc.hash}input  content:(example  china  city)
name           label            sortorder
wuhan       wuhan   city�__���                     0
beijing     beijing city��ъ��                     1
dalian      dalian  city�_���_                     2
shanghai    shanghai  city��_���                3
guangzhou    guangzhou  city�_���_          4



${esc.hash}${esc.hash}below  is a new structure ,name  servitems(�ύ�_���܎�_) ,i  use  Custom Fields type,fieldVelocityVarName  is  departsel(�ύ�_��Ĭ�Ѭ)���it work  well.
${esc.hash}${esc.hash}description  This code will pull a list of content into a custom field and create a select box for each result.



${esc.hash}${esc.hash}set(${esc.dollar}_qk = "+structureName:Departstruct +(conhost:${esc.dollar}host.identifier conhost:SYSTEM_HOST)")
${esc.hash}set(${esc.dollar}_qk = "+structureName:Departstruct ")
${esc.hash}set(${esc.dollar}cons = ${esc.dollar}dotcontent.pull(${esc.dollar}{_qk},0,"Departstruct.sortorder asc"))

 <select dojoType="dijit.form.FilteringSelect" autocomplete="true" id="${esc.dollar}{field.getVelocityVarName()}" name="${esc.dollar}{field.getFieldContentlet()}" ${esc.dollar}{field.isReadOnly()}?"readonly=\"\"":"">
	  <option value="" class="optionSelectField">please select...</option>
	  ${esc.hash}foreach(${esc.dollar}con in ${esc.dollar}cons)
	    ${esc.hash}set(${esc.dollar}name=${esc.dollar}!{con.name})
	    ${esc.hash}set(${esc.dollar}pairvalue=${esc.dollar}!{con.label})
	    ${esc.hash}set(${esc.dollar}selected = "")
	  ${esc.hash}if (${esc.dollar}UtilMethods.isSet(${esc.dollar}value))
	       ${esc.hash}set(${esc.dollar}compareValue = ${esc.dollar}{value})
	  ${esc.hash}elseif  ( ${esc.dollar}UtilMethods.isSet(${esc.dollar}defaultValue))
	        ${esc.hash}set(${esc.dollar}compareValue = ${esc.dollar}{defaultValue})
	  ${esc.hash}else   
	       ${esc.hash}set(${esc.dollar}compareValue = "") 
	  ${esc.hash}end
	     ${esc.hash}if (  (${esc.dollar}UtilMethods.isSet(${esc.dollar}compareValue)) &&(${esc.dollar}compareValue.equalsIgnoreCase(${esc.dollar}{name}))  )
                            ${esc.hash}set(${esc.dollar}selected = "SELECTED")
         ${esc.hash}end  
	    
       ${esc.hash}${esc.hash}set(${esc.dollar}compareValue = (${esc.dollar}UtilMethods.isSet(${esc.dollar}value) ? ${esc.dollar}{value} : (${esc.dollar}UtilMethods.isSet(${esc.dollar}defaultValue) ? ${esc.dollar}{defaultValue} : "")))
     
         <option value="${esc.dollar}!{name}" ${esc.dollar}{selected}> ${esc.dollar}!{pairvalue}</option>
   
	  ${esc.hash}end
</select>

Have you created code you'd like to share with the dotCMS community?

Share your code Become a Contributor