luci_tutorials icon indicating copy to clipboard operation
luci_tutorials copied to clipboard

How can I add Javascript code to a Luci model page?

Open rubo77 opened this issue 10 years ago • 3 comments

Maybe you can add a tutorial page for how to enhance your interface files with javascript code?

Maybe you can help here too: http://stackoverflow.com/questions/24864265/add-javascript-in-openwrt-luci-interface

I would like to add a javascript in the gluon webinterface So i you enter a pair of coordinates into one the latitude input field, the logitute part is automatically moved to the other input field.

rubo77 avatar Jul 21 '14 11:07 rubo77

I found out: you can add some custom javascript in the view for that model.

But I guess, there is a better solution for that?

rubo77 avatar Jul 21 '14 13:07 rubo77

Yes, you can add custom java-script for the view. Or you can change the "template" attribute of an object to point at a custom template. For a few good examples of this check out the one off classes defined at the bottom of the cbi.lua file.

http://luci.subsignal.org/trac/browser/luci/trunk/modules/base/luasrc/cbi.lua#L1774

seamustuohy avatar Jul 30 '14 13:07 seamustuohy

Oh and BTW, this would look something like this in the model.

custom_java_script = section:option(DummyValue "none")
custom_java_script.template = "path/to/javascript.js"

custom_html = section:option(DummyValue "none")
custom_html.template = "path/to/html/file.htm"

seamustuohy avatar Jul 30 '14 13:07 seamustuohy