On 11/17/2019 9:13 PM, Paul Mazaitis wrote:

Hi everyone,

First: apologies for the long email; this got a little complicated.

Summary: there may be a bug in setting up calculate field for widgets?

it's more that javascript in pdf is kind of unreliable and can interfere in all kind of ways with settings in the viewer

so, what you need to do it

- play safe (only use actions that don't relate to something clever in the viewer, and calculat eis one of them)
- be redundant (hook into several actions)
- disable the spell checker
- enable javascript
- disable some security stuff
- use the debugger (which can be erratic but at least you can see something; in my older acrobat doesn't seem to work with field related scripts)
- put code in functions (easier to debug)

and

- cross your fingers

Here's something to play with ... note the Number conversion!

\usemodule[fields]

\starttext

\setupinteraction [state=start]

\startJSpreamble {whatever} used now
function recalculate() {
    var a_fld = this.getField("A");
    var b_fld = this.getField("B");
    var t_fld = this.getField("T");
    var a_val = Number(a_fld.value);
    var b_val = Number(b_fld.value);
    var t_val = a_val + b_val;
    t_fld.value = String(t_val);
    console.clear ;
    console.println("A: "+a_val) ;
    console.println("B: "+b_val) ;
    console.println("T: "+t_val) ;
    console.println("?: "+t_fld.value) ;
    this.dirty = true;
}
\stopJSpreamble

\setupfield
  [numField]
  [reset,horizontal]
  [height=2pc,
   rulethickness=1pt,
   afterkey=JS(recalculate{}),
   focusout=JS(recalculate{}),
   framecolor=lightgrey]

\setupfield
  [totalField]
  [reset,horizontal]
  [height=2pc,
   rulethickness=1pt,
   option=readonly,
   framecolor=lightgrey]

\definefield[A][line][numField]  [0]
\definefield[B][line][numField]  [0]
\definefield[T][line][totalField][0]

A: \field[A]\par
B: \field[B]\par
T: \field[T]\par

\stoptext



-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
       tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-----------------------------------------------------------------
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to