Avatar

Mobile Events Listener Not working

Christopher Mason

Hi, I cant seem to get the mobile events to work.  I have created a button but it wont work on my mobile device.  Also i am adding a iframe chart that doesnt show up on mobile.    Not sure what I am doing wrong.   Below is an example of what i am doing. Thanks

kintone.events.on(['mobile.app.record.create.show', 'mobile.app.record.edit.show','mobile.app.record.detail.show', 'mobile.app.record.create.change.symbol', 'mobile.app.record.edit.change.symbol' ], function(event) {

var record = event.record;

//code to add a chart here:
var symbol = event.record.symbol.value;
var chartSpaceElement = kintone.app.record.getSpaceElement('chart');
chartSpaceElement.innerHTML = ""
var chart = document.createElement('div');
chart.innerHTML = `<div class="tradingview-widget-container"><div id="tradingview_58cad"></div><div class="tradingview-widget-copyright"><a href="https://www.tradingview.com/symbols/NASDAQ-AAPL/" rel="noopener" target="_blank"><span class="blue-text">Maxim Chart</span></a> by Masken Solutions</div></div>`
chartSpaceElement.appendChild(chart);

new TradingView.widget(
{
"width": 980,
"height": 610,
"symbol": `${symbol}`,
// "interval": "D",
"timezone": "Etc/UTC",
"theme": "light",
"style": "1",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"enable_publishing": false,
"withdateranges": true,
"range": "6m",
"hide_side_toolbar": false,
"allow_symbol_change": true,
"details": true,
"news": [
"headlines"
],
"container_id": "tradingview_58cad"
}
);


// stock price calculations code below

if (event.type === "mobile.app.record.create.show" || event.type === "mobile.app.record.edit.show") {
var buttonElement = document.createElement('button');
buttonElement.id = "calculateButton";
buttonElement.innerText = 'Calculate';

//replace button element with blank space
kintone.app.record.getSpaceElement('button').appendChild(buttonElement);

//add eventlistener to button
buttonElement.addEventListener('click', function(e){
var recordData = kintone.app.record.get();
var record = recordData.record;
var rebalancingRate = record.rebalancingRate.value;
var startDate = new Date(record.startDate.value);

Follow 2 followers
0

1 comment

Avatar
Yuzo Arai 0 votes

Hello Christopher!

I noticed that on the part where you obtain the space field element, it's not the mobile version.
Instead of:
 kintone.app.record.getSpaceElement
it should be
 kintone.mobile.app.record.getSpaceElement

There might be others in the script like that, so can you recheck your script and see if it works after fixing them?

This list might be useful upon checking it:
 Kintone JavaScript API List
 https://developer.kintone.io/hc/en-us/articles/360009339614-Kintone-JavaScript-API-List

0
Comment actions Permalink