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
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?
😃
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.
- 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)
- 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;
…
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;
…
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
I can directly fill in my list by entering data-value
.
Really a good idea, it works fine. Thanks !
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