How can I have a luci form which takes one value and updates multiple uci fields?

I am trying to create a new simple luci page which allows you to set a WiFi ssid and have it used for both 2GHz and 5GHz.

Here I have it for setting default_radio0 and that works fine. How can get luci to also save this as default_radio1?

'use strict';
'require view';
'require form';

return view.extend({
        render: function () {
                var m, s, o;
                var sectionName;

                m = new form.Map('wireless', 'WiFi',
                        'Here you can choose your WiFi network name'
                );

                s = m.section(form.NamedSection, 'default_radio0');

                o = s.option(form.Value, 'ssid', _('WiFi network name:'),
                        'ssid goes here'
                );
                o.datatype = 'maxlength(32)';
                o.placeholder = 'somethingssid';

                return m.render();
        }
});

Sorry, I only have experience doing it with Lua, not javascript. For new WebUI framework, I believe you'd have to create an RPCD script.

o = s.option(form.Value, 'ssid', _('WiFi network name:'), ...);

...

o.write = function(section_id, value) {
    m.data.set('wireless', 'default_radio0', 'ssid', value);
    m.data.set('wireless', 'default_radio1', 'ssid', value);
}

Or more generically (not depending on the specific naming of radio iface sections):

o = s.option(form.Value, 'ssid', _('WiFi network name:'), ...);

...

o.write = function(section_id, value) {
    var sections = m.data.sections('wireless', 'wifi-iface');
    for (var i = 0; i < sections.length; i++) 
        m.data.set('wireless', sections[i]['.name'], 'ssid', value);
}
2 Likes

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