From d7a69118bc08281bf3b7804f4e0beaf68074b68d Mon Sep 17 00:00:00 2001 From: Guillaume Lajarige Date: Thu, 11 Feb 2016 15:24:29 +0000 Subject: [PATCH] Prerequisites to the custom fields SVN:trunk[3909] --- js/form_field.js | 26 +++++++++++++++++++------- js/form_handler.js | 3 --- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/js/form_field.js b/js/form_field.js index 016cec1c9..479f5e8cf 100644 --- a/js/form_field.js +++ b/js/form_field.js @@ -9,7 +9,9 @@ $(function() // default options options: { - validators: null + validators: null, + validate_callback: 'validate', // When using an anonymous function, use the 'me' parameter to acces the current widget : function(me){ return me.validate(); }, + get_current_value_callback: 'getCurrentValue' }, // the constructor @@ -25,12 +27,22 @@ $(function() me.options.validators = data; }); this.element - .bind('validate', function(event, data){ - return me.validate(); - }); - this.element - .bind('get_current_value', function(event, data){ - return me.getCurrentValue(); + .bind('validate get_current_value', function(event, data){ + var callback = me.options[event.type+'_callback']; + + if(typeof callback === 'string') + { + return me[callback](); + } + else if(typeof callback === 'function') + { + return callback(me); + } + else + { + console.log('Form field : callback type must be a function or a existing function name of the widget'); + return false; + } }); }, // called when created, and later when changing options diff --git a/js/form_handler.js b/js/form_handler.js index 6aeb1dec3..9e701ccb7 100644 --- a/js/form_handler.js +++ b/js/form_handler.js @@ -295,9 +295,6 @@ $(function() { this.buildData.style_code += ' '+ field.css_inline; } - // JS widget itop.form_field - var json_validators = (field.validators != undefined) ? JSON.stringify(field.validators) : 'null'; - this.buildData.script_code += '; $("[' + this.options.field_identifier_attr + '=\'' + field.id + '\']").form_field({ validators: ' + json_validators + ' });'; }, buildForm: function()