1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary CharLimitFieldValidator 5 */ 6 7 goog.provide('Banana.Controls.Decorators.CharLimitFieldValidator'); 8 9 goog.require('Banana.Controls.Decorators.Validator'); 10 11 /** @namespace Banana.Controls.Decorators.CharLimitFieldValidator */ 12 namespace('Banana.Controls.Decorators').CharLimitFieldValidator = Banana.Controls.Decorators.Validator.extend( 13 /** @lends Banana.Controls.Decorators.CharLimitFieldValidator.prototype */ 14 { 15 /** 16 * Creates a character limit field validator 17 * Use setMaxChars to set max. Use this control only with input controls 18 * 19 * @param {Banana.Controls.InputControl} c 20 * @constructs 21 * @extends Banana.Controls.Decorators.Validator 22 */ 23 init : function(c) 24 { 25 this._super(c); 26 27 this.showIndicator = false; 28 }, 29 30 /** 31 * @override 32 * @param {String} data 33 */ 34 validateData : function(data) 35 { 36 if (!data) 37 { 38 return true; 39 } 40 41 return (data.length <= this.maxChars); 42 }, 43 44 /** 45 * @param {int} max characters 46 * @return {this} 47 */ 48 setMaxChars : function(max) 49 { 50 this.maxChars = max 51 return this; 52 }, 53 54 /** 55 * @override 56 * if no infotext is supplied then we show max character as warning tag 57 */ 58 getInfoText : function() 59 { 60 return this.infoText || 'Max '+this.maxChars+' chars'; 61 } 62 });