Skip to content

🅰️ Mono module that serialize an form object and emits it.

License

Notifications You must be signed in to change notification settings

jxmono/form-serializer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

71 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Form Serializer

Mono module that serialize an form object and emits it.

Documentation

Module configuration

The event module name is configurable (the default value is serializedForm).

"miidName": {
    "module": "github/jillix/form-serializer/MODULE_VERSION"
  , "roles": [MONO_ROLES]
  , "config": {
        "html": "/path/to/html/file.html"
        "eventName": "editList"
      , "validators": {
            "fillForm": "namespace.form_serializer.validateData"
        }
      , "onFill": {
            "binds": [BIND_OBJECTS]
        }
      , "listen": {EVENT_OBJECTS}
    }
  , "operations": {
        "loadForm": {
            "roles": [1]
          , "params": [{
                "forms": {
                    "formId1": "/public/html/forms/myForm.html"
                }
            }]
        }
    }
}

Public functions

Function Name Parameters Description
fillForm (data) data: an object, as first function parameter. Use config.onFille.binds to fill the form. Fill the form using Bind Mono Module. The binds are configurable from config.onFill.binds. See for more information Bind module.
showError (err) err: a string, as first function parameter. It's the error message that appears in the alert Shows an error
clearErrors () No parameters Clear all errors
loadForm options: object (formId is required), callback: callback function (optional) Loads dinamically a form as pointed in [#2](#2)

How to use

Place in the module HTML data-field and data-value atributes.

Value Description Default value Required Example
data-field Name of the key from object. No default value. Yes data-field="author"
data-value It's the name of the function how the value will be taken. val No (will take the default value) data-value="text"
data-params Params of jQuery function set as data-value. No default value Not required. data-params="checked"
data-convert-to The data type. Can be one of the following values:
  • string
  • number
  • boolean
No default value Not required. data-convert-to="boolean"
data-delete-if If provided, the field will be deleted if it's equal with the attribute value. No default value Not required. data-delete-if=""

Example

<form>
    <input type="text" data-field="author" value="Ionică Bizău" />
    <input type="checkbox" data-field="visible" data-value="prop" data-params="checked" value="Ionică Bizău" />
</form>

When the form above will be submitted the following JSON object will be generated and emited:

{
    "author": "IonicaBizau"
  , "visible": false
}

Changelog

v0.4.0

  • transferred the module to the new jxMono organization
  • updated Bind to v0.4.0, Events to v0.4.0, Utils to v0.2.0

v0.3.2

  • Updated to Bind v0.3.3, Utils v0.1.8 and Events v0.3.1

v0.3.1

  • Changed owner to jillix
  • Updated to Bind v0.3.1

v0.3.0

  • Upgraded deps

v0.2.5

  • Updated to Events v0.1.11 and Utils v0.1.2

v0.2.4

  • Removed close button from alert

v0.2.3

  • Updated to Events v0.1.10

v0.2.2

  • Bind v0.2.2 and Utils v0.1.1

v0.2.1

  • added data-delete-if attribute feature
  • deleted deprecated findValue and findFunction because util library is already imported and contains these methods

v0.2.0

  • Added Utils in dependencies
  • Added LICENSE
  • Upgraded Events module
  • Added Converters (see data-convert-to)
  • Added dot notation feature
  • Override config.onFill.binds if a second argument is provided in fillForm function

v0.1.3

  • Fixed loadForm method callback callback

v0.1.2

  • Added loadForm method. See #2 for details.

v0.1.1

  • Updated to Events v0.1.8 and Bind v0.2.1

v0.1.0

  • initial release

About

🅰️ Mono module that serialize an form object and emits it.

Resources

License

Stars

Watchers

Forks

Packages

No packages published