Friday 20 October 2006 5:49:25 am
<b>my object :</b>
FilmSelect [Enhanced Object relation]
Utilisateur [Enhanced Object relation]
DateHeureAchat [Date et heure] (datetime) buy date
EtatSelect [Énumération] (enum-list)
element Sélection 10 element Achat 20 <b>in the page :</b>
{*formulaire d'appel*}
<form method="post" action={"powercontent/action/"|ezurl} name="addcart" style="display:block" >
<input type="hidden" name="NodeID" value="" />
<input type="hidden" name="ClassID" value="35" />
<input type="hidden" name="RedirectURIAfterPublish" value="/{$node.url_alias}"/>
<input type="hidden" name="filmselect" value="">
<input type="hidden" name="utilisateur" value="">
<input type="hidden" name="etatselect" value="10">
<input type="hidden" name="CreateButton" value="ajouter"/>
</form>
<b>in the submit form :</b>
{*fonction de remplissage du formulaire*}
{literal}
<script>
function remplitForm()
{
{/literal}
// recupereration des différents éléments du formulaire
var x=document.panier.elements ;
//construction des élements enhaced relation object
var film = "ContentObjectAttribute_data_object_relation_id_list_"+{$content_attributes[0].id}+"[empty]" ;
var util = "ContentObjectAttribute_data_object_relation_id_list_"+{$content_attributes[1].id}+"[empty]" ;
{literal}
// parcoure des element et selection des valeurs
for (i=0;i<x.length;i++){
if(x[i].type == 'select-one'){
if(x[i].name == film){
for(j = 0 ; j < x[i].length;j++){
if(x[i][j].value=={/literal}{ezhttp('filmselect')}{literal}){
x[i][j].selected = 'selected' ;
}
}
}
if(x[i].name == util){
for(j = 0 ; j < x[i].length;j++){
if(x[i][j].value=={/literal}{ezhttp('utilisateur')}{literal}){
x[i][j].selected = 'selected' ;
}
}
}
}
}
{/literal}
var mode={if eq(ezhttp('CreateButton'),'ajouter')}'Sélection'{else}'Achat'{/if};
//remplissage des champs dates
document.panier.ContentObjectAttribute_datetime_year_{$content_attributes[2].id}.value = {currentdate()|datetime( 'custom', '%Y' )} ;
document.panier.ContentObjectAttribute_datetime_month_{$content_attributes[2].id}.value = {currentdate()|datetime( 'custom', '%m' )} ;
document.panier.ContentObjectAttribute_datetime_day_{$content_attributes[2].id}.value = {currentdate()|datetime( 'custom', '%d' )} ;
document.panier.ContentObjectAttribute_datetime_hour_{$content_attributes[2].id}.value = {currentdate()|datetime( 'custom', '%H' )} ;
document.panier.ContentObjectAttribute_datetime_minute_{$content_attributes[2].id}.value = {currentdate()|datetime( 'custom', '%i' )} ;
{literal}
for (i=0;i<x.length;i++){
if(x[i].type =='radio') {
if(x[i].value == mode){
x[i].checked = 'checked';
}else{
x[i].checked = '';
}
}
}
//document.panier.PublishButton.click();
}
</script>
{/literal}
<form name="panier" enctype="multipart/form-data" method="post" action={concat("/content/edit/",$object.id,"/",$edit_version,"/",$edit_language|not|choose(concat($edit_language,"/"),''))|ezurl}>
<table class="layout" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" style="display:none">
<input type="hidden" name="DiscardConfirm" value="0" />
{include uri="design:content/edit_attribute.tpl"}
<input class="defaultbutton" type="submit" name="PublishButton" value="acheter"/>
<input class="button" type="submit" name="DiscardButton" value="annuler" />
</td>
</tr>
</table>
</form>
<b>explication : </b> this code pre-fill too the datetime,enhaced object relation and enum-list. The comment is in french, sorry. explications : second part :
in javascript fonctions
- Get all elements of my form - Construct my var with the id of enhaced object relation.
- browse all my element with the select-one and equal to my var. - set the value with ezhttp. - the is the current date of my server. - browse all my radio button and set the value (not generic and not optimize) - the last line simulate a click in the button publish. It's a speed code, no optimization, no generic code Pierre-Jean
|