Commit 8a36db62 authored by KR Moorhouse's avatar KR Moorhouse

Merge branch 'issue#3619' into 'develop'

Issue#3619

Closes #3619

See merge request ninja-forms/ninja-forms!3616
parents 9c5e60ea 35031a21
/**
* Handles actions related to number field settings.
*
* @package Ninja Forms builder
* @subpackage Fields - Edit Field Drawer
* @copyright (c) 2015 WP Ninjas
* @since 3.0
*/
define( [], function() {
var controller = Marionette.Object.extend( {
initialize: function() {
// Respond to requests for field setting filtering.
nfRadio.channel( 'number' ).reply( 'before:updateSetting', this.updateSetting, this );
},
/**
* Resets value if user enters value below min value or above max value
*
* @since 3.0
* @param Object e event
* @param backbone.model fieldModel field model
* @param string name setting name
* @param backbone.model settingTypeModel field type model
* @return int 1 or 0
*/
updateSetting: function( e, fieldModel, name, settingTypeModel ) {
var minVal = parseInt( settingTypeModel.get( 'min_val' ) );
var maxVal = parseInt( settingTypeModel.get( 'max_val' ) );
e.target.value = parseInt( e.target.value );
/*
* if we gave a min value set, revert to that if the user enters
* a lower number
*/
if( 'undefined' != typeof minVal && null !== minVal ){
if ( e.target.value < minVal ) {
fieldModel.set('value', minVal);
e.target.value = minVal;
}
}
/*
* if we gave a max value set, revert to that if the user enters
* a higher number
*/
if( 'undefined' != typeof maxVal && null !== maxVal ){
if ( e.target.value > maxVal ) {
fieldModel.set('value', maxVal);
e.target.value = maxVal;
}
}
return e.target.value;
}
});
return controller;
} );
\ No newline at end of file
......@@ -35,6 +35,7 @@ define(
'controllers/app/fieldset',
'controllers/app/toggleSetting',
'controllers/app/buttonToggleSetting',
'controllers/app/numberSetting',
'controllers/app/radioSetting',
'controllers/app/itemControls',
'controllers/app/mergeTags',
......@@ -141,6 +142,7 @@ define(
Fieldset,
ToggleSetting,
ButtonToggleSetting,
NumberSetting,
RadioSetting,
ItemControls,
MergeTags,
......@@ -278,6 +280,7 @@ define(
new ChangeSettingDefault();
new ToggleSetting();
new ButtonToggleSetting();
new NumberSetting();
new RadioSetting();
new DrawerSettingChildView();
new FieldsEditActive();
......
......@@ -361,7 +361,64 @@ define( ['views/app/drawer/mergeTagsContent', 'views/app/drawer/settingError'],
} else {
return '';
}
}
},
/**
* Renders min and/or max attributes for the number input
*
* @returns {string}
*/
renderMinMax: function() {
var minMaxStr = '';
// if we have a min value set, then output it
if( 'undefined' != typeof this.min_val && null != this.min_val && jQuery.isNumeric( this.min_val ) ) {
minMaxStr = minMaxStr + "min='" + this.min_val + "'";
}
// if we have a max value set, then output it
if( 'undefined' != typeof this.max_val && '' != this.max_val && jQuery.isNumeric( this.max_val ) ) {
minMaxStr = minMaxStr + " max='" + this.max_val + "'";
}
return minMaxStr;
},
/**
* Returns a string to let the user know the min and/or max
* value for the field
*
* @returns {string}
*/
renderMinMaxHelper: function() {
var minMaxHelperStr = '';
// if we have a min value output it to the helper text
if( 'undefined' != typeof this.min_val && null != this.min_val && jQuery.isNumeric( this.min_val ) ) {
// empty string? then add '('
if( 0 == minMaxHelperStr.length ) {
minMaxHelperStr = "(";
}
minMaxHelperStr = minMaxHelperStr + nfi18n.minVal + ": " + this.min_val;
}
// if we have a max value output it to the helper text
if( 'undefined' != typeof this.max_val && '' != this.max_val && jQuery.isNumeric( this.max_val ) ) {
// empty string? then add '('
if( 0 == minMaxHelperStr.length ) {
minMaxHelperStr = "(";
} else {
// else, we know we have a min so add a comma
minMaxHelperStr = minMaxHelperStr + ", ";
}
minMaxHelperStr = minMaxHelperStr + nfi18n.maxVal + ": " + this.max_val;
}
// if not an empty string, then add ')'
if( 0 < minMaxHelperStr.length ) {
minMaxHelperStr = minMaxHelperStr + ")";
}
return minMaxHelperStr;
}
}
},
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
File mode changed from 100755 to 100644
......@@ -74,6 +74,8 @@ return apply_filters( 'ninja_forms_action_email_settings', array(
'group' => 'advanced',
'label' => __( 'How long in days until subs expire?', 'ninja-forms' ),
'value' => '90',
'min_val' => 1, // new minimum value setting
'max_val' => null, // new maximum value setting
'width' => 'one-half',
'deps' => array(
'set_subs_to_expire' => 1
......
......@@ -74,6 +74,8 @@ return apply_filters( 'ninja_forms_i18n_builder', array(
'fieldDataDeleteMsg' => sprintf( __( '%sThis will also DELETE all submission data associated with this field.%sYou will not be able to retrieve this data later!%s' ), '<p>', '</p><p>', '</p><br />' ),
'delete' => __( 'Delete' ),
'cancel' => __( 'Cancel' ),
'minVal' => __( 'Min Value' ),
'maxVal' => __( 'Max Value' ),
'valueChars' => __( 'In order to prevent errors, values may only contain'
. ' a specific subset of characters ( a-z, 0-9, -, _, @, space ). You'
. ' can use the option label in your success message(s) or email action(s) by adding'
......
......@@ -468,7 +468,10 @@ Label Three, value-three, 3
<script id="tmpl-nf-edit-setting-number" type="text/template">
<label for="{{{ data.name }}}">{{{ data.label }}} {{{ data.renderTooltip() }}}
<input type="number" class="setting" id="{{{ data.name }}}" value="{{{ data.value }}}" placeholder="{{{ ( 'undefined' != typeof data.placeholder ) ? data.placeholder : '' }}}" />
<input type="number" class="setting" id="{{{ data.name }}}"
value="{{{ data.value }}}" {{{ data.renderMinMax() }}}
placeholder="{{{ ('undefined' != typeof data.placeholder ) ? data.placeholder : '' }}}" />
<em>{{{ data.renderMinMaxHelper() }}}</em>
</label>
</script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment