luci icon indicating copy to clipboard operation
luci copied to clipboard

widget error checks

Open systemcrash opened this issue 1 year ago • 0 comments

FAO: @jow- @dannil @stokito

How to trigger error checks in (custom) widgets? Specifically around load, save, and create times? If I set .readonly to false, this immediately triggers the error if it is empty at those times, even for widgets not yet visible. But if I try to return any non true value from a function assigned to .validate, those values are lost. Validate is about validating input received when the user finished interacting with the widget, and does not seem to yield anything at any other time (even though it runs).

function validateBlah(section_id, s) {

	return _('blah');
	...
	return true;
}

...

	o.validate = validateBlah;

Some widget examples: cbiRichListValue in network.js, and the one in https://github.com/openwrt/luci/pull/6247, and generally anything from widgets.js of luci-base, i.e. NetworkSelect.

A widget is generally intended to handle choices such that picking a wrong value is not possible. But sooner or later we need to check combinations and trigger an error.

If I use .bind() on the function, it's not much better. Same effect if I directly assign e.g.:

	o.validate = function(section_id, s) {
		...
	}

I've written my own widget to handle cutom-tlv for the upcoming luci-app-lldpd, and it works fine. Just need error checks to happen at the right time, i.e. sanity checks for loaded values.

form.* interact fine with .validate - they work as intended - at load, save and create time (i.e. separate .save, .cfgvalue etc functions need not be defined.

What's missing? A parse: somewhere?

systemcrash avatar Mar 27 '24 17:03 systemcrash