diff --git a/src/opnsense/www/js/opnsense.js b/src/opnsense/www/js/opnsense.js index 2493c338a..842e1e1f3 100644 --- a/src/opnsense/www/js/opnsense.js +++ b/src/opnsense/www/js/opnsense.js @@ -44,13 +44,13 @@ function htmlDecode(value) { /** * * Map input fields from given parent tag to structure of named arrays. + * When a type_formatter attribute exists on the input element, this will be called with the val() content first * * @param parent tag id in dom * @return array */ function getFormData(parent) { - - var data = {}; + let data = {}; $("#"+parent+" input,#"+parent+" select,#"+parent+" textarea" ).each(function() { if ($(this).prop('id') === undefined || $(this).prop('id') === "") { // we need an id. @@ -96,8 +96,13 @@ function getFormData(parent) { // deserialize the field content - used for JS maintained fields node[keypart] = sourceNode.data('data'); } else { - // regular input type - node[keypart] = sourceNode.val(); + // regular input type, might need a parser to convert to the correct format + // (attribute type_formatter as function name) + if (sourceNode.attr('type_formatter') !== undefined && window[sourceNode.attr('type_formatter')] !== undefined) { + node[keypart] = window[sourceNode.attr('type_formatter')](sourceNode.val()); + } else { + node[keypart] = sourceNode.val(); + } } } }); @@ -142,13 +147,27 @@ function setFormData(parent,data) { targetNode.tokenize2().trigger('tokenize:clear'); } targetNode.empty(); // flush - $.each(node[keypart],function(indxItem, keyItem){ - var opt = $("