Scribus Forums

Scribus => Scripts and Plugins => Topic started by: t.hai on December 14, 2016, 11:00:36 AM

Title: Script in Javascript with data and 2 checkbox?
Post by: t.hai on December 14, 2016, 11:00:36 AM
Hi,
i need help :(
I have a file data.xfdf, who's containts the data example: p1_data_name ="Dubois", p1_data_firstname="Mark", p1_data_title="Men",...
In scribus my PDF (Test.pdf) I created the fields with name "p1_data_name" is not difficult,
but i have 2 checkbox "Women" and "Men" and i would like to open my PDF, which read the data and make true the good checkbox.

My script in Javascript:

function pret()
{
  $(document).ready(titre());
}

function titre(){
   var title = this.getField("p1_data_titre").value; //fields containts the title "Men" Or "Women"
   var men = this.getField("Men");  //checkbox Men
   var women = this.getField("Women");

   app.alert('Titre:'+title.value); // undefined at the opening pdf

   if (title.value == "Women") {
           women.value = "Yes";
           men.value = "Off";
   } else {
           women.value = "Off";
           men.value = "Yes";
   }
}

But It don't work... :(

i think the problem is that my PDF is not ready, and it make error variable not undefined.

Do you have solutions to offer me?

Sorry my language is french, sorry if there are grammar mistakes or understanding.

Thank you for read.
Title: Re: Script in Javascript with data and 2 checkbox?
Post by: a.l.e on December 14, 2016, 11:08:40 AM
hi t

can you please share a .sla and pdf that shows the issue?

ciao
a.l.e
Title: Re: Script in Javascript with data and 2 checkbox?
Post by: t.hai on December 14, 2016, 01:38:49 PM
Hi a.l.e,

Thank you for your help :)

And my file data.xfdf contains:

<?xml version="1.0" encoding="UTF-8"?>
<?xfa generator="T.H" APIVersion="1"?>
<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">
   <fields>
      <field name="p1_data_title"><value>Men</value></field>
      <field name="p1_data_name"><value>Dubois</value></field>
      <field name="p1_data_firstname"><value>Mark</value></field>
      <field name="p1_data_nele"><value>13.05.1990</value></field>
      <field name="p1_data_origine"><value>Saint-Ours</value></field>
      <field name="p1_data_ocanton"><value>FR</value></field>
      <field name="p1_data_locdl"><value>Cernier</value></field>
      <field name="p1_datasup_dateDay"><value>14.12.2016</value></field>
      <field name="p1_datasup_lieudate"><value>Neuchatel, le 14.12.2016</value></field>
   </fields>
</xfdf>

T.hai

[attachment deleted by admin]