FoxInCloud
value VFP / JS
Gravatar is a globally recognized avatar based on your email address. value VFP / JS
  Vincent H.
  All
  May 23, 2020 @ 02:47am

Hi Thierry,

In a function (drag & drop) created in HTMLgen(), I have to retrieve a value from a VFP function by passing a parameter retrieved in JS.

var mValue = jQuery (this).text();

Then,

mValue = VFP_fonction (mValue)

I'm totally confused ...
Thanks in advance

Gravatar is a globally recognized avatar based on your email address. re: value VFP / JS
  FoxInCloud Support - Thierry N.
  Vincent H.
  May 23, 2020 @ 02:51am

I'm totally confused ...

So am I!
Here is what I understand: you need to get, on client side (browser) a value from a VFP function (calculated on server side)…

Am I right on track?

Gravatar is a globally recognized avatar based on your email address. re: value VFP / JS
  Vincent H.
  FoxInCloud Support - Thierry N.
  May 23, 2020 @ 03:00am

😃

Here is my wcHTMLGen() code :

Mvalproc = "";
 + "var ebxBlur = function(event){" + RetChar;
    + "var ebx = jQuery('#" + m.wcID + "');" + RetChar;
    + "event.type = 'blur';" + RetChar;
    + "return this.EventRequest('DOMEvent', event, ebx[0], ebx.val());" + RetChar;
 + "}" + RetChar;
 + "jQuery('#" + .wcID + " li')" + RetChar;
 + ".on('dragstart', function(event){" + RetChar;
    + "var mValeur = jQuery(this).text();" + RetChar;
    + "event.originalEvent.dataTransfer.setData('text/plain', mValeur + '\n');" + RetChar;
    + "event.originalEvent.dataTransfer.dropEffect='copy';" + RetChar;
 + "})";
 + ".on('dragend', function(event){" + RetChar;
    + "window.setTimeout(jQuery.proxy(ebxBlur, FoxInCloud), 200, event);" + RetChar;
 + "})";
 + ";"

mValeur represents the text of the option dragged.
I would like to replace this text (to insert into my textarea) with a value obtained from a VFP function to which I must pass mValeur.

Gravatar is a globally recognized avatar based on your email address. re: value VFP / JS
  FoxInCloud Support - Thierry N.
  Vincent H.
  May 23, 2020 @ 06:12am
  1. Implement a method in your VFP listbox (I name it the same as the function you need to call):
define class … as xxxLst
…
function myFunction(mValeur)
return myFunction(mValeur)
  1. modify the .wcHTMlgen() code as follows:
…
 + ".on('dragstart', function(event){" + RetChar;
    + "var mValeur = jQuery(this).text();" + RetChar;
    + "if (FoxInCloud.MethExec("
    + "event /* {en} event or event source object {fr} événement ou son objet source */"
    + ",'" + .wcID + "' /* {en} id of HTML object matching VFP object holding the method {fr} id HTML de l'objet VFP détenant la méthode */"
    + ",'myFunction' /* {en} method {fr} méthode */"
    + ", mValeur /* {en} Value to be passed as method parameter - undefined for none {fr} Valeur à passer en paramètre à la méthode - undefined n'en passe aucun */"
    + ", true /* {en} Synchronous request {fr} Requête synchrone */"
    + ")) mValeur = FoxInCloud.uValue;" + RetChar;
    + "event.originalEvent.dataTransfer.setData('text/plain', mValeur + '\n');" + RetChar;
    + "event.originalEvent.dataTransfer.dropEffect='copy';" + RetChar;
…
Gravatar is a globally recognized avatar based on your email address. re: value VFP / JS
  FoxInCloud Support - Thierry N.
  Vincent H.
  May 24, 2020 @ 01:29am

There is a more simple solution: use a listbox with 2 columns, 1 for display and 1 for the result of the function (value); then add the value as a data attribute to the <li> element and use this data in .dragstart().

procedure yourListbox.Init

local ii
select display, ' ' from yourTable into array this.waRowSource
for ii = 1 to _Tally
  this.waRowSource[m.ii, 2] = yourFunction(this.waRowSource[m.ii, 1])
endfor
this.columnCount = 2
this.boundColumn = 2
this.RowSourceType = 5 && array
this.RowSource = 'this.waRowSource'
…
return dodefault()

procedure yourListbox.wcHTMLgen

local ii
for ii = 1 to alen(this.waRowSource, 1)
  this.wcHMTL = this.wcHMTL + '<li data-value="' + cHTMLattribValue(this.waRowSource[m.ii, 2]) + '">' + this.waRowSource[m.ii, 1] + '</li>'
endfor
…
 + ".on('dragstart', function(event){" + RetChar;
    + "var mValeur = jQuery(this).data('value');" + RetChar;
    + "event.originalEvent.dataTransfer.setData('text/plain', mValeur + '\n');" + RetChar;
    + "event.originalEvent.dataTransfer.dropEffect='copy';" + RetChar;
…
Gravatar is a globally recognized avatar based on your email address. re: value VFP / JS
  Vincent H.
  FoxInCloud Support - Thierry N.
  May 24, 2020 @ 03:25am

Thanks Thierry, we changed planet ... Oups, I have not seen your last response. So, for information (with the penultimate solution)

On dragend, I always get:

function (tcValue, tcType){ // Valeur de propriété selon le type de awProps.dbf et awTxt.prg!cTypeJS()
    switch (tcType.trim().substr(0,1).toUpperCase()){
    case 'S':
      return tcValue;
    case 'B':
      return tcValue === 'true';
    case 'N':
      tcValue = tcValue.replace(',', '.').replace(' ', '');
      return (tcValue.indexOf('.') > -1) ? parseFloat(tcValue) : parseInt(tcValue, 10);
    case 'D':
      return eval(tcValue); // new Date(...)
    case 'O':
      return JSON.parse(tcValue);
    default:
      return null;
    }
  }

On Dragstart, mValeur has the good value

I'm going to try your other solution

Gravatar is a globally recognized avatar based on your email address. re: value VFP / JS
  Vincent H.
  FoxInCloud Support - Thierry N.
  May 24, 2020 @ 03:47am

I can directly fill in my list by entering data-value.
Really a good idea, it works fine. Thanks !

Gravatar is a globally recognized avatar based on your email address. re: value VFP / JS
  FoxInCloud Support - Thierry N.
  Vincent H.
  May 25, 2020 @ 04:18am

Another simplification…

select display;
  , cast(yourFunction(display) as M);
  from yourTable;
  into array this.waRowSource

instead of

local ii
select display, ' ' from yourTable into array this.waRowSource
for ii = 1 to _Tally
  this.waRowSource[m.ii, 2] = yourFunction(this.waRowSource[m.ii, 1])
endfor
© 1996-2020