LuCI JS: refresh DummyValue after button click

Hi everyone!
Can someone help me with my luci app. I want to load values to form.DummyValue after click on button.

I have function, which call ubus method and return json object:
CLI:
ubus call myapp status '{"config": "myconfig"}'
and return:

{
  "aaa" : "aaa_value",
  "bbb" : "bbb_value"
}

LuCI JS:

var requestAll = rpc.declare({
	object: 'myapp',
	method: 'status',
	params: [ 'config' ],
	expect: { '': {} }
});
...
o = s.option(form.DummyValue, 'aaa', _('AAA'));
o = s.option(form.DummyValue, 'bbb', _('BBB'));

o = s.option(form.Button, 'refresh');
o.inputtitle = _('Refresh');
o.onclick = function(section_id) {
	return requestAll(section_id).then(function(data) {
		//does not work
		var aaa = document.getElementById('cbid.myapp.mysection.aaa')
		aaa.value = data.aaa;
		//work
		ui.addNotification(null, [
			E('p', [ _('AAA value: "%s"; BBB value: "%s" ').format(data.aaa,data.bbb) ])
		]);
	});
}

If I replace "form.DummyValue" to "form.Value" and "cbid.myapp.mysection.aaa" to "widget.cbid.myapp.mysection.aaa" it works. But I need an immutable DummyValue.

Could someone tell me where I am going wrong?

I replace "form.DummyValue" by "DummyValueExt":

o = s.option(DummyValueExt, 'aaa', _('AAA'));
o = s.option(DummyValueExt, 'bbb', _('BBB'));

Create new widget:

var DummyValueExt = form.DummyValue.extend({
	renderWidget: function(section_id, option_index, cfgvalue) {
		return E([], [
			E('input', {
				'id': this.cbid(section_id),
				'type': 'text',
				'readonly': false
			})
		]);
	}
});

After that, I can update the fields after the button is clicked. But I cannot copy these values from the web page. So, I change input to div:

var DummyValueExt = form.DummyValue.extend({
	renderWidget: function(section_id, option_index, cfgvalue) {
		return E([], [
			E('div', {
				'class': 'cbi-value-field',
				'id': this.cbid(section_id),
				'style': 'color:#c73d3d;margin-left:0' 
			})
		]);
	}
});

and replace

aaa.value = data.aaa;

to

aaa.textContent = data.aaa;

Cheers

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.