diff --git a/source/development/frontend/view_js_helpers.rst b/source/development/frontend/view_js_helpers.rst index ef6a4cb1..c928e73b 100644 --- a/source/development/frontend/view_js_helpers.rst +++ b/source/development/frontend/view_js_helpers.rst @@ -127,10 +127,36 @@ saveFormToEndpoint :code:`saveFormToEndpoint(url, formid, callback_ok, disable_dialog, callback_fail)` is the opposite of :code:`mapDataToFormUI()` and retrieves the data from the form and sends it to the configured (url) endpoint as json structure. +Underneath this function uses :code:`getFormData(parent)` defined in `opnsense.js` which is responsible for extracting values from +different form types such as :code:`` and :code:` + +Which could be implemented in the form javascript as: + +.. code-block:: javascript + + function my_convert_to_int_function(payload) + { + if (/^[+-]?[0-9]*$/.test(payload)) { + return parseInt(payload); + } else { + return payload; + } + } The response data looks similar to the example data in mapDataToFormUI, but more condensed since selections will be returned as single (separated) values, such as :code:`lan,wan` if both options where set. +Using the example with the function above, a valid integer would offer a json object similar to :code:`{"myform": {"myintval": 1}}`, +unparsable data would look like :code:`{"myform": {"myintval": "1x"}}`, in which case backend validations are able to feedback validation results. + ---------------------------- updateServiceControlUI