
Security News
Node.js Drops Bug Bounty Rewards After Funding Dries Up
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.
mod-build
Advanced tools
This package is created to be used on microsites that contain forms. It helps streamline development by providing flexible reusable components for forms such as:
modSite (mod-site.js) for handling form validation, switching steps, processing and submitting data to the backend, and handling backend responses;modUtils for variuos related methods used in modSite or thank you page;mod-site is added as a dependant package (in package.json) to all S3 sites by default.
Init modForm for windows trade example:
modForm.init({
vertical: 'windows'
});
| Option | Required | Default value | Description |
|---|---|---|---|
| vertical | Yes | null | Form's vertical. Possible options are: solar, windows, roof, hvac |
| form | Yes | $('#form') | jQuery form object |
| formLoadingCls | Yes | form--loading | CSS class for a loading state of the form |
| stepsSelector | Yes | [data-bind="step"] | CSS selector for form's steps |
| stepActiveCls | Yes | step--active | active step CSS class |
| tcpaCopy | Yes | $('#tcpa-copy') | jQuery object of a TCPA copy block |
| maskedPhoneFields | No | $('#form').find(':input[name="homePhone"]') | jQuery object of inputs to add phone mask to |
| numericsOnlyFields | No | $('#form').find(':input[name="zip"], :input[name="zip1"]') | jQuery object of digits only inputs (e.g. phone and zip) |
| addressField | No | $('#form').find(':input[name="address"]') | jQuery object of an address field |
| stateField | No | $('#form').find(':input[name="state"]') | jQuery object of a state field |
| cityField | No | $('#form').find(':input[name="city"]') | jQuery object of a city field |
| zip1Field | No | $('#form').find(':input[name="zip1"]') | jQuery object of secondary zip field |
| zipField | Yes | $('#form').find(':input[name="zip"]') | jQuery object of primary zip field |
| repairField | No | $('#form').find(':input[name="repair"]') | jQuery object of repair field |
| hvacWouldReplaceBlock | No | $('#hvac-would-replace-block') | HVAC only. Block that contains wouldReplace control. |
| hvacSystemTypeField | No | $('#form').find(':input[name="hvacSystemType"]') | HVAC only. System type field. |
| hvacFuelTypeBlock | No | $('#hvac-fuel-type-block') | HVAC only. Block that contains hvacFuelType control. |
| hvacSystemTypesWithFuel | No | 'Central Heating', 'Boiler' | HVAC only. Array of hvac system types (lowercase) that require fuel type selection. |
| fieldErrorCls | Yes | has-error | CSS error class. |
| errorParentCls | No | parent-error | CSS class of a field parent which will get fieldErrorCls on error. |
| gaTracker | No | main | GA tracker to use |
| thankyouPage | Yes | /thankyou/ | Thankyou page URL. |
| landingPage | No | window.location.href | Landing page URL. |
| Callback | Options | Return | Description |
|---|---|---|---|
| formSubmittingCallback | formData | formData | Fires right before form is submitted. Allows to change data that will be sent to the API. If you return false inside the callback, the submission will stop. |
| formSubmitSuccessCallback | response | Fires when submitting form data to server was successful. Returns server response. Return false inside this callback to stop form from redirecting to TY page. | |
| formSubmitErrorCallback | response | Fires when submitting form data to server returned an error. Returns server response. | |
| stepChangingCallback | oldStepId, stepId | stepId | Fires right before the step switches. Return stepId to switch to that step or false to stop |
| stepChangedCallback | oldStepId, stepId | Fires right after the step was switched. | |
| zipCodeValidated | geoData | Fires right after the zip code has been validated on the server. Returns geo data: city and state for this zip code. |
Below are most useful methods of the modForm object.
| Method | Options | Return | Description |
|---|---|---|---|
| showStep | stepId | Shows form's step by id. | |
| showNextStep | Shows form's next step. | ||
| showPrevStep | Shows form's prev step. | ||
| getCurrentStep | $step | Returns form's current step as a jQuery object. | |
| isCurrentStepLast | true or false | Returns true/false if current step is the last one in the form. | |
| getFormData | Object | Returns form's data as a key/value object. |
We use Handlebars.js as a template engine. It allows us to use includes, loops, variables, etc. in our templates.
| Variable | Type | Example | Description |
|---|---|---|---|
| year | Integer | {{year}} | Current year. |
| tcpa | Function | {{#x 'this.tcpa("Get matches", "Modernize")'}}{{/x}} | Shows TCPA copy. You can pass in button name and company name as properties. |
| formErrors | Object | {{formErrors.firstName}} | Form errors. Support properties: firstName, lastName, streetAddress, city, state, zip, email, homePhone, tradeQuestion |
| states | Array | {{#each states}} ... {{/each}} | |
| solar.shade | Array | {{#each solar.shade}} ... {{/each}} | |
| solar.electricBill | Array | {{#each solar.electricBill}} ... {{/each}} | |
| windows.repair | Array | {{#each windows.repair}} ... {{/each}} | |
| windows.repair | Array | {{#each windows.repair}} ... {{/each}} | |
| windows.hear | Array | {{#each windows.hear}} ... {{/each}} | |
| windows.style | Array | {{#each windows.style}} ... {{/each}} | |
| hvac.project | Array | {{#each hvac.project}} ... {{/each}} | |
| hvac.repair | Array | {{#each hvac.repair}} ... {{/each}} | |
| hvac.hvacSystemFuelTypes | Array | {{#each hvac.hvacSystemFuelTypes}} ... {{/each}} | |
| hvac.hvacSystemTypes | Array | {{#each hvac.hvacSystemTypes}} ... {{/each}} | |
| hvac.hvacFuelTypes | Array | {{#each hvac.hvacFuelTypes}} ... {{/each}} | |
| roofing.repair | Array | {{#each roofing.repair}} ... {{/each}} | |
| roofing.material | Array | {{#each roofing.material}} ... {{/each}} |
Example: including VWO & GTM snippets into a project:
<!DOCTYPE html>
<head lang="en">
{{ fileInclude 'node_modules/mod-site/src/templates/_partials/scripts/visual-website-optimizer.html' }}
{{ fileInclude 'node_modules/mod-site/src/templates/_partials/scripts/google-tag-manager-head.html' }}
...
</head>
<body>
{{ fileInclude 'node_modules/mod-site/src/templates/_partials/scripts/google-tag-manager-body.html' }}
...
You can use variables from mod-site package and project itself inside any template.
Example: displaying hvacSystemType select using data from mod-site:
<select class="form-control" name="hvacSystemType" data-required="nonempty">
<option value="">- Select system -</option>
{{#each hvac.hvacSystemTypes}}
<option value="{{this.value}}">{{this.name}}</option>
{{/each}}
</select>
More on using variables and conditions can be found on Handlebars.js website.
modForm object is flexible, and you can pass you own jQuery selector for steps, but the following markup is default:
<!-- Form -->
<form class="form" id="form" method="" action="" novalidate="">
<!-- Step 1 -->
<div class="step step--active" data-bind="step" id="step-1">
...
</div>
<!--/Step 1 -->
<!-- Step 2 -->
<div class="step" data-bind="step" id="step-2">
...
</div>
<!--/Step 2 -->
<!-- Step 3 -->
<div class="step" data-bind="step" id="step-3">
...
<div class="form-group">
<button class="btn btn-primary" type="submit">
Get matches →
</button>
</div>
<div class="tcpa-copy">
<input name="originLeadId" id="originLeadId" type="hidden" />
<input name="leadToken" id="leadid_token" type="hidden" />
<input id="leadid_tcpa_disclosure" type="hidden" />
<label for="leadid_tcpa_disclosure" id="tcpa-copy">
{{#x 'this.tcpa("Get matches")'}}{{/x}}
</label>
</div>
</div>
<!--/Step 3 -->
</form>
<!--/Form -->
When user clickes on submit button inside step 1 (or submits it using Enter from a text field), modForm will loop through all required fields inside step 1 and validate them. If there's an invalid field, it will be highlighted and the form won't be switched to the next step.
If step is valid, modForm will:
zip or zip1, it will freeze the form and validate its value with the backend:
You can use modSite callbacks and methods to alter the logic (e.g. to switch to specific step when user selected homeowner = No).
modForms supports the following validation methods:
Validation method for a control is set in html attribute data-required.
Example: required email control with error message
<div class="parent-error">
<input type="email" name="email" placeholder="Email" class="form-control" data-required="email" />
<div class="form-error">
{{formErrors.email}}
</div>
</div>
More details about the markup:
data-required="email" on input defines validation method<div class="parent-error"> will get class has-error if this field is not valid{{formErrors.email}} is a default error message for invalid email fieldmodForm requires the following files to work:
Default options for modForm can be found in mod-form.js file (with comments). The only required setting is vertical.
Example: setting up modForm for a windows form
modForm.init({
vertical: 'windows'
});
This project is licensed under the MIT license.
Copyright (c) 2017 Modernize.
FAQs
Share components for S3 sites.
The npm package mod-build receives a total of 312 weekly downloads. As such, mod-build popularity was classified as not popular.
We found that mod-build demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.