Skip to content

Instantly share code, notes, and snippets.

View travist's full-sized avatar

Travis Tidwell travist

View GitHub Profile
if ($scope.action) {
var method = submissionData._id ? 'put' : 'post';
$http[method]($scope.action, submissionData, {
disableJWT: true,
headers: {
Authorization: undefined,
Pragma: undefined,
'Cache-Control': undefined
}
}).success(function(submission) {
@travist
travist / formio-submission-index-search.js
Created September 7, 2016 04:17
Form.io Submission Index Requests
/**
* This will request all submissions where they provided "Smith" in the Last Name field.
*
* GET - https://yourproject.form.io/yourform/submission?data.lastName=Smith
*/
var request = require("request");
var options = {
method: 'GET',
url: 'https://yourproject.form.io/yourform/submission',
qs: {'data.lastName': 'Smith'},
@travist
travist / state.json
Last active October 1, 2016 21:13
U.S. States GeoCode API Results
{
"Alabama": {
"address_components": [{
"long_name": "Alabama",
"short_name": "AL",
"types": ["administrative_area_level_1", "political"]
}, {
"long_name": "United States",
"short_name": "US",
"types": ["country", "political"]
@travist
travist / debounce.js
Last active October 2, 2021 11:28
How to debounce a $scope.$watch for Angular.js.
['$scope', function($scope) {
var debounce = function(cb) {
var timeout = null;
return function(data) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(function() {
cb(data);
}, 200);
@travist
travist / force.js
Last active October 30, 2016 23:37
Force Field Validation Errors in Form.io
var forceFieldError = function(key, error) {
var formioFormScope = angular.element('[name="formioForm"]').scope();
var formioScope = formioFormScope.$parent;
var formioForm = formioFormScope.formioForm;
var component = FormioUtils.getComponent(formioScope.form.components, key);
component.customError = error;
formioForm.$pristine = false;
formioForm.$valid = false;
formioForm[key].$setValidity('custom', false);
formioForm[key].$pristine = false;
@travist
travist / embed.html
Created November 2, 2016 12:59
Form.io CodePen
<p data-height="600" data-theme-id="light" data-slug-hash="xVyMjo" data-default-tab="result" data-user="travist" data-embed-version="2" data-pen-title="Form.io Form Building and Rendering" class="codepen">See the Pen <a href="http://codepen.io/travist/pen/xVyMjo/">Form.io Form Building and Rendering</a> by Travis Tidwell (<a href="http://codepen.io/travist">@travist</a>) on <a href="http://codepen.io">CodePen</a>.</p>
<script async src="https://production-assets.codepen.io/assets/embed/ei.js"></script>
@travist
travist / autoincrement.js
Last active December 2, 2016 14:26
Auto-incrementing value in Form.io
angular.module('myApp')
.controller('FormController', ['$scope', 'Formio', function($scope, Formio) {
$scope.form = null;
$scope.submission = {data: {}};
var formio = (new Formio('https://myproject.form.io/myform'));
var getAutoIncrement = function(fieldName, cb) {
formio.loadSubmissions({params: {sort: '-data.' + fieldName, limit: 1}}).then(function(subs) {
var value = 0;
if (subs.length) {
@travist
travist / image.css
Last active December 7, 2016 02:48
Viewing images with Form.io
.center-loader {
font-size: 2em;
position: absolute;
left: 50%;
top: 50%;
margin-top: -0.5em;
margin-left: -0.5em;
}
@travist
travist / transform.js
Created January 4, 2017 17:26
Transform address
var header = true;
module.exports = function(record, next) {
if (header) {
// Ignore the header row.
header = false;
return next();
}
next(null, {
data: {
propertyId: record[0],
@travist
travist / FormSubmissionController.js
Created January 23, 2017 17:58
Manual Form.io API
angular.module('myApp')
.controller('FormSubmissionController', [
'Formio',
'$http',
function(Formio, $http) {
$scope.form = null;
// Render the form manually. This will not call the Form.io API when it is submitted, but rather
// just trigger the formSubmission event.
(new Formio('https://myproject.form.io/myform')).loadForm().then(function(form) {