bonjour,
Voici le script pour centrer un champ horizontalement en milieu de page.
nbChamps=this.numFields;
if (nbChamps) {
var leChamp="- Liste des champs -";
var listeChamps="var listeChamps \= \{\""+leChamp+"\": "+(nbChamps+1)+",";
for (var i=0; i < nbChamps; i++) {
var nomChamp=this.getNthFieldName(i);
if (typeof this.getField(nomChamp).page!="object") {
listeChamps+="\""+nomChamp+"\": "+(-1*(i+1)).toString()+",";
} else {
for (var j=0; j<this.getField(nomChamp).page.length; j++) listeChamps+="\""+nomChamp+"."+j+"\": "+(-1*(i+1)).toString()+",";
}
}
var listeChamps=listeChamps.substring(0, listeChamps.length-1);
listeChamps+="\}";
eval(listeChamps);
var bDialogue={
initialize: function(bDialogue) {
this.loadDefaults(bDialogue);
},
loadDefaults: function(bDialogue) {
bDialogue.load({
LCha: listeChamps,
})
},
validate: app.trustedFunction(function(bDialogue) {
app.beginPriv();
var oRslt=bDialogue.store();
var elements=bDialogue.store()["LCha"];
var testOK=true;
for (var i in elements) {
if (elements>0) {
valeurListe=listeChamps;
nomListe=i;
}
}
if (valeurListe>0 && (oRslt["nmCh"]=="" || (/^\s+|\s+$/gm).test(oRslt["nmCh"]))) {
var txt="Veuillez sélectionner ou indiquer un nom de champ.";
var testOK=false;
} else {
if (valeurListe>0) nmChamp=oRslt["nmCh"];
else nmChamp=nomListe;
try {
laPage=getField(nmChamp).page;
} catch(e) {
var txt="Le champ \""+nmChamp+"\" n'existe pas.";
var testOK=false;
}
}
if (!testOK) app.alert(txt,3);
return testOK;
app.endPriv();
}),
description: {
name: "Centrer un champ",
elements: [
{
type: "view",
elements: [
{
type: "view",
alignment: "align_fill",
elements: [
{
type: "static_text",
name: "Nom du champ",
font: "dialog",
bold: true,
},
{
type: "static_text",
name: "Sélectionnez...",
},
{
type: "popup",
item_id: "LCha",
width: 150,
alignment: "align_fill",
},
{
type: "static_text",
name: "ou indiquez son nom :",
},
{
type: "edit_text",
item_id: "nmCh",
height: 20,
alignment: "align_fill",
},
]
},
{
type: "gap",
height: 5
},
{
type: "ok_cancel",
},
]
},
]
}
};
if("ok"==app.execDialog(bDialogue)){
var aRect=this.getField(nmChamp).rect;
aRect[0]=(this.getPageBox()[2]/2)-(aRect[2]/2);
aRect[2]=(this.getPageBox()[2]/2)+(aRect[2]/2);
this.getField(nmChamp).rect=aRect;
}
} else app.alert("Il n'y a pas de champ dans ce document.",3);
@+
😎