Skip to content

Instantly share code, notes, and snippets.

@kstover
kstover / customDatePicker.js
Last active February 2, 2024 10:06
Customising Ninja Forms date picker field
/*
* When our date picker loads, we want to modify some of picker settings.
*
* We want to:
* 1) Modify our month labels with a different string.
* 2) Disable specific dates so that they can't be selected.
*
*
* This object will listen to date pickers as they initialize so that we can modify settings.
*/
@kstover
kstover / nf-after-load.js
Created November 10, 2016 18:47
Ninja Forms Three - After a form has loaded
// Create a new object for custom validation of a custom field.
var nameSpaceController = Marionette.Object.extend( {
initialize: function() {
this.listenTo( nfRadio.channel( 'form' ), 'render:view', this.doCustomStuff );
},
doCustomStuff: function( view ) {
var formModel = view.model; // formModel will be a Backbone model with all of our form data.
var formID = formModel.get( 'id' ); // We can use .get( 'setting' ) get get any of our form settings.
// Create a new object for custom validation of a custom field.
var mySubmitController = Marionette.Object.extend( {
initialize: function() {
this.listenTo( Backbone.Radio.channel( 'field-4', 'change:field', this.nameChange ) );
},
nameChange: function( el, model ) {
// Split your model value
var value = model.get( 'value' );
@kstover
kstover / backbone-wp-tutorial-base-admin.js
Created December 10, 2015 21:22
Intro to Backbone & WordPress Tutorial - Part 1 - Base Admin.js File
jQuery( document ).ready( function( $ ) {
/**
* JS goes here
*/
} );
/**
* Work around for Require, Radio, and WordPress.
*
* Returns the WordPress-loaded version of Underscore for use with things that need it and use Require.
*
* @since 3.0
* @return Object Underscore Object
*/
define( function() {
return _;
/**
* Work around for Require, Radio, and WordPress.
*
* Returns the WordPress-loaded version of Backbone for use with things that need it and use Require.
*
* @since 3.0
* @return Object Backbone Object
*/
define( function() {
return Backbone;
@kstover
kstover / nf-sample-field-type-localization-data.js
Created November 4, 2015 18:54
Sample data for localizing field types.
this.collection = new fieldTypeCollection( [
{
id: 'textbox',
nicename: 'Textbox',
alias: [ 'input' ],
parentType: '',
settingGroups: new fieldTypeSettingGroupCollection( [
{
name: '',
display: true,
/*
* This variable holds all of our custom strings for form display.
* It can be accessed and used by our JS code.
*/
var nfDynamicContent = {
beforeForm: '',
beforeFields: '<h4>Please check your fields carefully!</h4>',
afterFields: '',
afterForm: ''
}
<?php
function ninja_forms_custom_display( $before_fields, $form_id ) {
// Output text received from the database before our field output.
$text = get_stuff_from_somewhere_else( $form_id );
$before_fields .= '<h4>'. $text . '</h4>';
return $before_fields;
}
add_filter( 'nf_frontend_before_form', 'ninja_forms_custom_display', 10, 2 );
<?php
function ninja_forms_custom_display( $form_id ) {
// Output text received from the database before our field output.
$text = get_stuff_from_somewhere_else( $form_id );
echo '<h4>'. $text . '</h4>';
}
add_action( 'ninja_forms_display_before_form', 'ninja_forms_custom_display' );