I am trying to build my own Twitter Bot, but I'm stuck at the point where it needs to press a button to continue to the next page. My Page is twitter.com/account/access and when the account is locked it will show javascript on account/access?js=1
with this JS I can obtain the ui_metrics which I need for the next payload. My problem is that I obtain an incorrect UI metrics. The code on account/access?js=1 looks like:
var fioDNpGxgmnkgCviIszx = function() {
$('.Button').prop('disabled', false);function CzHMSLRaxHitXCjrMvSI() {var aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=228;var a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29=234;var a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8=9;var a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=161;aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=~(aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4&aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4);a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428^a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428;a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8=~a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8;aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=function(XSlSY,HCUYy,sLRiq){function ABGhk(lYBbi){this.rbMeE=function(){return this.mQFmd^lYBbi;}};var JutGW={mQFmd:sLRiq};var kVGSg=new ABGhk(XSlSY);kVGSg.mQFmd=HCUYy;ABGhk.prototype=JutGW;return kVGSg.rbMeE()|(new ABGhk(HCUYy)).rbMeE();}(aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4,a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29,a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428);a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29=~(a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29&a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8);a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29=function(lHUyQ,vsVJI,HSoJI){var FtMNB=document.createElement('div');FtMNB.setAttribute('style','display:none;');document.getElementsByTagName('body')[0].appendChild(FtMNB);function RTiPq(xwdds,nrUno){for(var i=0;i<8;i++){var HyJWh=document.createElement('div');xwdds.appendChild(HyJWh);HyJWh.innerText=nrUno;if((nrUno&1)==0)xwdds=HyJWh;nrUno=nrUno>>1;}return xwdds;};function UWDtX(HyJWh,FtMNB,nrUno){if(!HyJWh||HyJWh==FtMNB) return nrUno%256;while(HyJWh.children.length>0)HyJWh.removeChild(HyJWh.lastElementChild);return UWDtX(HyJWh.parentNode,FtMNB,nrUno+parseInt(HyJWh.innerText));};var nrUno=UWDtX(RTiPq(RTiPq(RTiPq(FtMNB,lHUyQ),vsVJI),HSoJI),FtMNB,0);FtMNB.parentNode.removeChild(FtMNB);return nrUno;}(a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29,a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428,a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428);aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=function(SNUeY,wyMcY,jnUNa){var hPVCO=document.createElement('div');hPVCO.setAttribute('style','display:none;');document.getElementsByTagName('body')[0].appendChild(hPVCO);function jpszb(dsoIa,gVlrY){for(var i=0;i<8;i++){var kAZuz=document.createElement('div');dsoIa.appendChild(kAZuz);kAZuz.innerText=gVlrY;if((gVlrY&1)==0)dsoIa=kAZuz;gVlrY=gVlrY>>1;}return dsoIa;};function YvUDO(kAZuz,hPVCO,gVlrY){if(!kAZuz||kAZuz==hPVCO) return gVlrY%256;while(kAZuz.children.length>0)kAZuz.removeChild(kAZuz.lastElementChild);return YvUDO(kAZuz.parentNode,hPVCO,gVlrY+parseInt(kAZuz.innerText));};var gVlrY=YvUDO(jpszb(jpszb(jpszb(hPVCO,SNUeY),wyMcY),jnUNa),hPVCO,0);hPVCO.parentNode.removeChild(hPVCO);return gVlrY;}(aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4,a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8,a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8);a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8=~(a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8&a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29);a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=~(a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428&aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4);a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8=function(VtQxq,JDmbe,HodKX){var opBXC=document.createElement('div');opBXC.setAttribute('style','display:none;');document.getElementsByTagName('body')[0].appendChild(opBXC);function kGiOS(bmzQA,vkEop){for(var i=0;i<8;i++){var XdtAo=document.createElement('div');bmzQA.appendChild(XdtAo);XdtAo.innerText=vkEop;if((vkEop&1)==0)bmzQA=XdtAo;vkEop=vkEop>>1;}return bmzQA;};function wTYEk(XdtAo,opBXC,vkEop){if(!XdtAo||XdtAo==opBXC) return vkEop%256;while(XdtAo.children.length>0)XdtAo.removeChild(XdtAo.lastElementChild);return wTYEk(XdtAo.parentNode,opBXC,vkEop+parseInt(XdtAo.innerText));};var vkEop=wTYEk(kGiOS(kGiOS(kGiOS(opBXC,VtQxq),JDmbe),HodKX),opBXC,0);opBXC.parentNode.removeChild(opBXC);return vkEop;}(a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8,aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4,aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4);aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4^a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428;aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=function(JGvCJ,CZNEA,ajWfe){var Znwrh=document.createElement('div');Znwrh.setAttribute('style','display:none;');document.getElementsByTagName('body')[0].appendChild(Znwrh);function WcTis(SzYNI,TwoYh){for(var i=0;i<8;i++){var LQHaS=document.createElement('div');SzYNI.appendChild(LQHaS);LQHaS.innerText=TwoYh;if((TwoYh&1)==0)SzYNI=LQHaS;TwoYh=TwoYh>>1;}return SzYNI;};function Vukgq(LQHaS,Znwrh,TwoYh){if(!LQHaS||LQHaS==Znwrh) return TwoYh%256;while(LQHaS.children.length>0)LQHaS.removeChild(LQHaS.lastElementChild);return Vukgq(LQHaS.parentNode,Znwrh,TwoYh+parseInt(LQHaS.innerText));};var TwoYh=Vukgq(WcTis(WcTis(WcTis(Znwrh,JGvCJ),CZNEA),ajWfe),Znwrh,0);Znwrh.parentNode.removeChild(Znwrh);return TwoYh;}(aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4,a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8,a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428);aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=~(aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4&aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4);a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428|aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4;a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29=a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29|a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428;a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8=a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8&a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8;a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428|a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428;a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29=a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29^new Date(a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29*10000000000).getUTCDate();aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4^a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8;a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8=a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8^new Date(a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8*10000000000).getUTCDate();a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=~(a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428&a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29);a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=~a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428;a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29=a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29^a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8;aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=function(nEzec,EegJb,rTBen){function ARFVQ(esSLG){this.KVEMV=function(){return this.KkIOD^esSLG;}};var Xopnv={KkIOD:rTBen};var bpsMS=new ARFVQ(nEzec);bpsMS.KkIOD=EegJb;ARFVQ.prototype=Xopnv;return bpsMS.KVEMV()|(new ARFVQ(EegJb)).KVEMV();}(aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4,a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8,aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4);a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29=~(a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29&a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8);aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4=aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4|aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4;a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29=function(xZcWJ,PMxhH,qtcNS){var fkXcC=document.createElement('div');fkXcC.setAttribute('style','display:none;');document.getElementsByTagName('body')[0].appendChild(fkXcC);function KHNOb(OtqjX,AMEcs){for(var i=0;i<8;i++){var ncNlf=document.createElement('div');OtqjX.appendChild(ncNlf);ncNlf.innerText=AMEcs;if((AMEcs&1)==0)OtqjX=ncNlf;AMEcs=AMEcs>>1;}return OtqjX;};function MseEH(ncNlf,fkXcC,AMEcs){if(!ncNlf||ncNlf==fkXcC) return AMEcs%256;while(ncNlf.children.length>0)ncNlf.removeChild(ncNlf.lastElementChild);return MseEH(ncNlf.parentNode,fkXcC,AMEcs+parseInt(ncNlf.innerText));};var AMEcs=MseEH(KHNOb(KHNOb(KHNOb(fkXcC,xZcWJ),PMxhH),qtcNS),fkXcC,0);fkXcC.parentNode.removeChild(fkXcC);return AMEcs;}(a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29,a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428,a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29);a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428&a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8;a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428=a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428|a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428;a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8=a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8&a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29;return {'rf':{'aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4':aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4,'a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29':a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29,'a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8':a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8,'a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428':a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428},'s':'6rrNTyjkfhoyl3rg2FDTf66srNDiG4KC9a2WZxPhIuYibvxvbr9Ol3yvc_ZwJUEeRVYs_gdMA_wM1tWYenL1FxUF2ssilmw9D78EndVw6p8TWep5o9Yf53DZPG4-2l9yE-fvtPZ4er88FC2-8A65GgxuHtwt7b5M0E8_VjW882MzGUUgxWpJ4hUR7SAZs6vsXyriHQxSmQ6rPo3R1oCRBcRK1qSW9uxQYnex5ks-sXskXKyRsFnRLzpp0Jl5PTTsixiGDl0gI7mkMY38IAVTq_5U21QPuqG6hhFto5x-oA0SMV3y0M6tR0pseWolht3SOTL0u20xLA_MWoqd_XsVQgAAAYMOoR5n'};};
var zczpQtGKyj;
try {
zczpQtGKyj = JSON.stringify(CzHMSLRaxHitXCjrMvSI());
} catch (e) {
zczpQtGKyj = "exception " + e;
}
var inputs;
inputs = document.getElementsByName('ui_metrics');
for (var i = 0; i < inputs.length; i++) { inputs[i].value = zczpQtGKyj; }
}
var tiIKkHESFDEdobreOyeY = function() {
document.removeEventListener('DOMContentLoaded', tiIKkHESFDEdobreOyeY);
window.removeEventListener('load', tiIKkHESFDEdobreOyeY);
window.setTimeout(fioDNpGxgmnkgCviIszx);
}
if (document.readyState === 'complete') {
window.setTimeout(fioDNpGxgmnkgCviIszx);
} else {
document.addEventListener('DOMContentLoaded', tiIKkHESFDEdobreOyeY);
window.addEventListener('load', tiIKkHESFDEdobreOyeY);
}
};
yvOyxmAwGvnIARXVXhAk();
And the UI-Metrics look like this:
{"rf":{"aeb56204b7dfbb714b9f12941a38203fa093e8efdba351010742b86e6a3bd7c4":127,"a749666c3c90c3b92db8140aaf4bf3fdcaaaa9757e148533e0905da43f71fb29":-18,"a0142c051d9b8b9e324e86454560d9578058db0b686d12ac8c99685f9960c9a8":-60,"a67adf5c8e0cc5e48af38fcce933d4ea423490465329dc5804658da386048428":-48},"s":"6rrNTyjkfhoyl3rg2FDTf66srNDiG4KC9a2WZxPhIuYibvxvbr9Ol3yvc_ZwJUEeRVYs_gdMA_wM1tWYenL1FxUF2ssilmw9D78EndVw6p8TWep5o9Yf53DZPG4-2l9yE-fvtPZ4er88FC2-8A65GgxuHtwt7b5M0E8_VjW882MzGUUgxWpJ4hUR7SAZs6vsXyriHQxSmQ6rPo3R1oCRBcRK1qSW9uxQYnex5ks-sXskXKyRsFnRLzpp0Jl5PTTsixiGDl0gI7mkMY38IAVTq_5U21QPuqG6hhFto5x-oA0SMV3y0M6tR0pseWolht3SOTL0u20xLA_MWoqd_XsVQgAAAYMOoR5n"}
I made it obtain the text on the account/access?js=1 site and save it to a text file, where I made a function in python that obtains the "ui_metrics"
My code:
ui_metrics = ui_metrics_code.split(f'var {split_ui_metrics};')[0].split('return ')[-1].replace(';','').replace('\n','').split(" ")[0].replace("}}","}")
(where ui_metrics_code is the response text as above)
which returns in:
{'rf':{'d1a4aa70239ad88006075fef748959edb5e520a120c6c2c81d01ab5a85d6d40f':d1a4aa70239ad88006075fef748959edb5e520a120c6c2c81d01ab5a85d6d40f,'adcfa4d4340cd3b32e2d310686e79a56f2825b7eb6c6ce96b322f24423f0847d':adcfa4d4340cd3b32e2d310686e79a56f2825b7eb6c6ce96b322f24423f0847d,'baa9e1c07813efeff769ef29f5ce6864b07dad1bd2c2a472f95e1a9757e5c14c':baa9e1c07813efeff769ef29f5ce6864b07dad1bd2c2a472f95e1a9757e5c14c,'aa71801b588167a6a0e578c9043ce76001f2a66c2543b83081770643da54c04e':aa71801b588167a6a0e578c9043ce76001f2a66c2543b83081770643da54c04e},'s':'au5l9uA05MtyeXy05-64Mca8JuHi-uX7Zj-AhiRRySJa-4oPF-lvFyUSLE7RK8LnZ1w4KjQ-Nnko_cO7_s01h8VorlZcjqDczGw54WZ5UXVPdrHuuM9jmWKwJKZLF-c-GM96fPGPx0jr-S5GatOXfD_awkPI61HDeblfOKGZxqPQkQpTvGpAbcuur2QZr7MRzx5UMgmaZZDYjRqqPgDwWZADV-XBD9csj6lCsdirfNFvkHPQU4SmXwNHn2hZaN-ntfrMIpajcxhBCsX-S2HZpb9F4D6F16JtvVX9giQbm10KRuX3sGCxCy6x02n6p-eIj3f3lvmQxo1Bl23S1A2LZAAAAYMO9BRe'}
as you can see I miss the numbers like :127 and :-18 after the variables.
Im trying to understand where these numbers come from and how I can obtain these so I can get a correct UI-Metrics. Im pretty new in all this so im still trying to understand. Help would be really appreciated!
I have the following tag in my view.jsp:
<liferay-ui:input-localized id="message" name="message" xml="" />
And I know that I can set a XML and have a default value on my input localized. My problem is that I want to change this attribute with javascript. I am listening for some changes and call the function "update()" to update my information:
function update(index) {
var localizedInput= document.getElementById('message');
localizedInput.value = 'myXMLString';
}
Changing the value is only updating the currently selected language input (with the whole XML String). The XML String is correct, but I am not sure on how to update the XML for the input with javascript.
Is this possible?
PS: I have posted this in the Liferay Dev forum to try and reach more people.
After a week of studying the case and some tests, I think that I found a workaround for this. Not sure if this is the correct approach, but it is working for me so I will post my current solution for future reference.
After inspecting the HTML, I noticed that the Liferay-UI:input-localized tag creates an input tag by default, and then one more input tag for each language, each time you select a new language. Knowing that I created some functions with Javascript to help me update the inputs created from my liferay-ui:input-localized. Here is the relevant code:
function updateAnnouncementInformation(index) {
var announcement = announcements[index];
// the announcement['message'] is a XML String
updateInputLocalized('message', announcement['message']);
}
function updateInputLocalized(input, message) {
var inputId = '<portlet:namespace/>' + input;
var xml = $.parseXML(message);
var inputCurrent = document.getElementById(inputId);
var selectedLanguage = getSelectedLanguage(inputId);
var inputPT = document.getElementById(inputId + '_pt_PT');
inputPT.value = $(xml).find("Title[language-id='pt_PT']").text();
var inputEN = document.getElementById(inputId + '_en_US');
if (inputEN !== null) inputEN.value = $(xml).find("Title[language-id='en_US']").text();
else waitForElement(inputId + '_en_US', inputCurrent, inputId, xml);
var inputLabel = getInputLabel(inputId);
if (selectedLanguage == 'pt-PT') inputLabel.innerHTML = '';
else inputLabel.innerHTML = inputPT.value;
if (selectedLanguage == 'pt-PT') inputCurrent.value = inputPT.value;
else if (inputEN !== null) inputCurrent.value = inputEN.value;
else waitForElement(inputId + '_en_US', inputCurrent, inputId, xml);
}
function getSelectedLanguage(inputId) {
var languageContainer = document.getElementById('<portlet:namespace/>' + inputId + 'Menu');
return languageContainer.getElementsByClassName('btn-section')[0].innerHTML;
}
function getInputLabel(inputId) {
var boundingBoxContainer = document.getElementById(inputId + 'BoundingBox').parentElement;
return boundingBoxContainer.getElementsByClassName('form-text')[0];
}
function waitForElement(elementId, inputCurrent, inputId, xml) {
window.setTimeout(function() {
var element = document.getElementById(elementId);
if (element) elementCreated(element, inputCurrent, inputId, xml);
else waitForElement(elementId, inputCurrent, inputId, xml);
}, 500);
}
function elementCreated(inputEN, inputCurrent, inputId, xml) {
inputEN.value = $(xml).find("Title[language-id='en_US']").text();
var selectedLanguage = getSelectedLanguage(inputId);
if (selectedLanguage == 'en-US') inputCurrent.value = inputEN.value;
}
With this I am able to update the liferay-ui:input-localized inputs according to a pre-built XML String. I hope that someone finds this useful and if you have anything to add, please let me know!
To change the text value of an element, you must change the value of the elements's text node.
Example -
xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue = "new content"
Suppose "books.xml" is loaded into xmlDoc
Get the first child node of the element
Change the node value to "new content"
I'm trying to create something to refresh the list of dates to all users every 30 seconds.
I dynamically create a table with the list of dates in my database using AJAX, the thing is that the refresh removes what the user was writing in the moment of the refresh so I'm saving what the user writes in javascript global variables, calling the refresh function, then filling the inputs with the information in the variables and focusing the input the user was on.
The thing is the inputs aren't filled nor focused.
this is my relevant code here:
var identificacionc = "";
var nombresc = "";
var apellidosc = "";
var telefonoc = "";
var posicionc = 0;
var ladoc = 0;
//This is called on input onfocus to record the id
function recuerdo(posicion, lado)
{
posicionc = posicion;
ladoc = lado;
}
function actualizar()
{
//This line is not relevant
listaragenda();
if (document.getElementById("datepicker").value != "")
{
//put the info in the global variables and it works even if they're dynamically created
identificacionc = document.getElementById("txtidentificacion" + posicionc).value;
nombresc = document.getElementById("txtnombres" + posicionc).value;
apellidosc = document.getElementById("txtapellidos" + posicionc).value;
telefonoc = document.getElementById("txttelefono" + posicionc).value;
//Here is where I call the function to refresh dates
listarcitas();
}
}
function listarcitas()
{
var objAjax = crearObjeto();
var fecha = document.getElementById("datepicker").value;
objAjax.open("POST", "clases/listarcitas.php", true);
objAjax.setRequestHeader("Content-type","application/x-www-form-urlencoded");
objAjax.onreadystatechange = function()
{
if (objAjax.readyState == 4 && objAjax.status == 200)
{
document.getElementById("citaslistadas").innerHTML = objAjax.responseText;
//Checks if any global variable is not empty to start to fill them with the info
//nothing inside this If works
//posicionc and ladoc have the correct values
if (identificacionc != "")
{
document.getElementById("txtidentificacion" + posicionc).value = identificacionc;
document.getElementById("txtnombres" + posicionc).value = nombresc;
document.getElementById("txtapellidos" + posicionc).value = apellidosc;
document.getElementById("txttelefono" + posicionc).value = telefonoc;
if (ladoc == 1)
{
document.getElementById("txtidentificacion" + posicionc).focus();
}
else if (ladoc == 2)
{
document.getElementById("txtnombres" + posicionc).focus();
}
else if (ladoc == 3)
{
document.getElementById("txtapellidos" + posicionc).focus();
}
else if (ladoc == 4)
{
document.getElementById("txttelefono" + posicionc).focus();
}
}
}
}
objAjax.send("fecha=" + fecha);
}
//the interval every 30s
window.setInterval("actualizar()", 30000);
Everything retrieved from AJAX works fine everything is listed, even in the web browser console I make alerts of the variables, set the values and focus the dynamically created inputs, everything works fine.
But why this is not working in the code?
Thanks in advance
The following script worked in IE8 but not in IE9:
function toggleSelect(fieldName)
{
var idx = fieldName.lastIndexOf("_");
var sub = fieldName.substring(19,idx);
if (document.findForm["cb_Row_PageAutoDelete_" + sub].checked) {
document.findForm["SHIP_QTY_" + sub].disabled=false ;
} else {
document.findForm["SHIP_QTY_" + sub].disabled=true ;
}
return true;
}
I can display the value of the SHIP_QTY field so I know it's on the page but the disable function does not work.
Thanks for your help.
If findForm is the name of the form, you want window.findForm rather than document.findForm. You can also just use the result of the other field's checked property directly rather than an if/else. So your code changes to:
function toggleSelect(fieldName)
{
var idx = fieldName.lastIndexOf("_");
var sub = fieldName.substring(19,idx);
window.findForm["SHIP_QTY_" + sub].disabled = window.findForm["cb_Row_PageAutoDelete_" + sub].checked;
return true;
}
I have two scripts in a file active_form.js
The first script hides a text entry when a radiobutton is checked and the second does the same thing when a value is selected in a list.
When there are alone, the both work but together my function GereControleRadio do nothing.
edit : the two scripts are called in the same form.
The code of my scripts :
function GereControleRadio(Controleur, LabelControle, Controle, Masquer) {
var objLabelControle = document.getElementById(LabelControle);
var objControle = document.getElementById(Controle);
if (Masquer=='1') {
objControle.style.visibility=(objControleur.checked==true)?'visible':'hidden';
objLabelControle.style.visibility=(objControleur.checked==true)?'visible':'hidden';
}
else {
objControle.disabled=(objControleur.checked==true)?false:true;
objLabelControle.disabled=(objControleur.checked==true)?false:true;
}
return true;
};
function GereControleList(LabelControle, Controle, val) {
var objLabelControle = document.getElementById(LabelControle);
var objControle = document.getElementById(Controle);
if (val != '1% Patronal') {
objControle.style.visibility='hidden';
objLabelControle.style.visibility='hidden';
}
else {
objControle.style.visibility='visible';
objLabelControle.style.visibility='visible';
}
return true;
};
The .js is called in my view.yml
And I call the functions :
echo $form['etage']->render(array("onCLick" => "GereControleRadio('logement_etage_Etage', 'numetage_label', 'numetage_form, '1');"))
echo $form['reservataire']->render(array("onChange" => "GereControleList('patronal', 'patronal_form', 'this.value');"))
I believe you just have 2 functions with conflicting global scope variable names. Try replacing "GereControleList" with this...
function GereControleList(LabelControle, Controle, val) {
var objLabelControle_ = document.getElementById(LabelControle);
var objControle_ = document.getElementById(Controle);
if (val != '1% Patronal') {
objControle_.style.visibility='hidden';
objLabelControle_.style.visibility='hidden';
}
else {
objControle_.style.visibility='visible';
objLabelControle_.style.visibility='visible';
}
return true;
};
I have found the error : in GereControleRadio, I have deleted a line.
var objControleur = document.getElementById(Controleur);