[TYPO3-project-formidable] majix, how to combine multiple clientData values

Alexander Rose alexander.rose at weirdbyte.de
Thu Nov 22 12:29:45 CET 2007


Hi

Am 21.11.2007 um 19:22 schrieb Alexander Rose:
[...]
>
> It works for me, now. It would be be nice to have something more
> general, e.g. you give a string with 'templated' javascript in it and
> an array with clientData 'references' to majixReplaceData. then the
> placeholders in the 'templated' js are replaced with the clientData
> references and a static script can be generated. what do you think?
>

I changed setHtml and setValue added evalUserFunc to api/base/rdt_box/ 
res/js/box.js as discribed below, so one can write (for box  
renderlets) something like:

$this->aORenderlets["field_c"]->majixReplaceData(
		  array('%v * %v',
		    array("clientData::field_a","clientData::field_b"),
		      2));

you have to state how many %v to replace with clientData 'references'  
because I don't know how to get the number of members of an js object?!


changes/additions to api/base/rdt_box/res/js/box.js, which doesnn't  
break current functionality - i guess.

     evalUserFunc: function(data){
       var clientData = data[1];
       var userFunc = data[0];
       var n = data[2];
       for(var i=0; i < n; i++){
	userFunc = userFunc.replace(/%v/, clientData[i]);
       }
       //alert(userFunc);
       return eval(userFunc);
     },

     setHtml: function(sHtml) {
       if(typeof(sHtml)=="object"){
	this.domNode().innerHTML = this.evalUserFunc(sHtml);
       } else {
	this.domNode().innerHTML = sHtml;
       }
     },

     setValue: function(sValue) {
       if(this.hasData()) {
	if(typeof(sValue)=="object"){
	  this.domNodeHidden().value = this.evalUserFunc(sValue););
	} else {
	  this.domNodeHidden().value = sValue;
	}
       }


Alex


More information about the TYPO3-project-formidable mailing list