Skip to content

Instantly share code, notes, and snippets.

View ngalluzzo's full-sized avatar

Nic Galluzzo ngalluzzo

  • Mode Analytics
  • Bakersfield, CA
View GitHub Profile
@ngalluzzo
ngalluzzo / signup_href.js
Last active August 29, 2015 14:22
Replace Signup href
$(document).on('knack-view-render.any', function () {
$('a.register').attr("href", "https://yourcustomURLhere")
})
@ngalluzzo
ngalluzzo / gist:85c9472e8a2badc54271
Created December 1, 2014 15:19
reload a page after submit
$(document).on('knack-record-update.view_78', function (event, view, record) {
location.reload();
});
@ngalluzzo
ngalluzzo / data-check.js
Last active September 1, 2022 16:20
insert your own errors
$(document).on('knack-view-render.view_194', function (event, view, data) {
var err_counter = 0;
/* Insert error panel. Hidden by default */
$("<div class='kn-message error' id='app-errors'></div>").insertBefore("#view_194");
$("#app-errors").hide();
/* Conditions to Check */
if (data.field_168 === "Yes") {
@ngalluzzo
ngalluzzo / tentative.js
Last active August 29, 2015 14:07
Highlight 1 Value Based on Other Value
// If Tentative Field = Yes, Highlight Start / End Dates on Table
$(document).on('knack-records-render.view_140', function (event, view, records) {
$("table tr").each(function () {
var tentative = $(this).children("td:nth-child(14)").text().trim();
var startDate = $(this).children("td:nth-child(5)");
var endDate = $(this).children("td:nth-child(6)");
if (tentative === "Yes") {
$(startDate).css('backgroundColor','yellow');
$(endDate).css('backgroundColor','yellow');
@ngalluzzo
ngalluzzo / changetitle.js
Last active August 29, 2015 14:07
Change Knack Page Title to View Name!
// If using Knack builder, declare this as a global function to be re-used
var changeTitle = function (view) {
document.title = view.name;
};
// Change the Page Title (Text shown in the Tab) to the View Name
$(document).on('knack-view-render.view_70', function (event, view, data) {
changeTitle(view);
});
@ngalluzzo
ngalluzzo / 1direction.js
Last active August 29, 2015 14:07
Conditional Redirects in KnackHQ
$(document).on('knack-view-render.view_186', function (event, view, data) {
// Remove view from DOM. I just want to access the view data
$('#view_186').remove();
// If customer hasn't signed terms, they cannot complete application and will be redirected to sign the terms
if(data.field_203 === 'No') {
alert('You must sign the Terms & Conditions before completing your application');
@ngalluzzo
ngalluzzo / knackredirect.js
Last active April 10, 2017 11:10
Redirect to a Knack Related Scene after Record Update
// On Knack Record Update, redirect to URL. I know this already exists in Knack, but in my case
// I wanted to direct the recently updated record to another view.
$(document).on('knack-record-update.view_173', function (event, view, record) {
window.location.replace('#employer/editplacement/' + record.id);
});
@ngalluzzo
ngalluzzo / KnackWrap.js
Created October 7, 2014 17:03
Group knack views into your own CSS classes
$(document).on('knack-scene-render.scene_41', function (event, scene) {
// Wrap just one view in a class
$("#view_165").wrap("<div class='fix-bottom'></div>");
// Wrap multiple views in the same div
$("#view_113, #view_114, #view_115, #view_116, #view_117, #view_118").wrapAll("<div class='fix-top'></div>");
@ngalluzzo
ngalluzzo / copyrecord.js
Last active October 25, 2022 18:23
Copy a Record!
// I took one of Knack's examples and tweaked it a bit to duplicate my own records since I needed this ASAP.
// This example works off of a record's detail view to access the data. I have not worked up a table solution yet.
// TODO: - Add connected records
// Change your view
$(document).on('knack-view-render.view_12', function (event, view, data) {
// Map new record fields with current record in view
var duplicateData = {
// If field is connection, we need to match the ID in order for Knack to pick it up
field_57: data.field_57_raw[0].id,
@ngalluzzo
ngalluzzo / $scope.submit
Created August 2, 2014 01:34
Submit only changed data in AngularJS KnackHQ app
$scope.submit = function(){
console.log($scope.myForm) //myForm created from name="myForm" on the <form> tag
angular.forEach($scope.myForm,function(value,key){
if(key[0] == '$') return; //ignore built in methods, they start with $
if(!value.$pristine){
//if pristine on the value is false, this means it is dirty and has been modified
//Access the actual value by value.$modelValue
var datatoedit = {};
datatoedit[key] = value.$modelValue;
console.log("The value for ",key,"has changed to ", value.$modelValue);