Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7022789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:37:39+00:00 2026-05-27T23:37:39+00:00

I have this plugin with the structure of boilerplate. My problem is to create

  • 0

I have this plugin with the structure of boilerplate. My problem is to create the event ‘controlEventoKeyUp’.
Be able to access the methods of the plugin, I had to ignore the plugin parameter bind('keyup',_{_plugin:_this_},_controlEventoKeyUp).
This solved my problem but I found a tidy way of doing this.

Can another solution there be with this model?

(function ($, window, document, undefined) {

    var pluginName = 'controlLenInput',
        defaults = {
            maxLen: 100,
            displanCantidadActual: null,
            textUppercase: false
        };

    // The actual plugin constructor
    function Plugin(element, options) {

        this.element = element;

        this.options = $.extend({}, defaults, options);

        this._defaults = defaults;
        this._name = pluginName;

        this.init();
    };

    Plugin.prototype.init = function () {

        $(this.element)
            .bind('keyup', { plugin: this }, controlEventoKeyUp)
            .trigger('keyup');
    };

    Plugin.prototype.asignarValorActual = function () {

        $(this.options.displanCantidadActual)
            .html('<span>' + (this.options.maxLen - $(this.element).val().length) + '</span>&nbsp;<span>caracteres pendientes</span>');

    };

    var controlEventoKeyUp = function (event) {

        var _plugin = event.data.plugin;

        if (_plugin.options.maxLen < $(this).val().length) {
            $(this).val($(this).val().substr(0, _plugin.options.maxLen));
        }
        else {
            _plugin.asignarValorActual();
        }

        if (_plugin.options.textUppercase) { 
            $(this).val($(this).val().toUpperCase());
        }

    };

    $.fn[pluginName] = function (options) {
        return this.each(function () {
            if (!$.data(this, 'plugin_' + pluginName)) {
                $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
            }
        });
    }

})(jQuery, window, document);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:37:39+00:00Added an answer on May 27, 2026 at 11:37 pm

    After looking over the boilerplate template, I could see that calling plugin, is recorded in “data” the instance of the plugin:

    $.data(this, 'plugin_' + pluginName, new Plugin(this, options));
    

    then, to retrieve the instance of the plugin for this element, simply, in the event, I get back it this way:

    var plugin = $.data(this, 'plugin_' + pluginName);
    

    so then would be the function of the event:

    var controlEventoKeyUp = function (event) {
    
        var _plugin = $.data(this, 'plugin_' + pluginName);
    
        if (_plugin.options.maxLen < $(this).val().length) {
            $(this).val($(this).val().substr(0, _plugin.options.maxLen));
        }
        else {
            _plugin.asignarValorActual();
        }
    
        if (_plugin.options.textUppercase) { 
            $(this).val($(this).val().toUpperCase());
        }
    
    }
    

    Edit

    As fires a “trigger” event, when I access the plugin with “$. data” creates an error, because it still is not there already.
    change so as to keep the plugin. in this way, I can access the plugin already loaded without error.

    // The actual plugin constructor
    function Plugin(element, options) {
    
        this.element = element;
    
        this.options = $.extend({}, defaults, options);
    
        this._defaults = defaults;
        this._name = pluginName;
    
        this.element['plugin_' + pluginName] = this;
        this.init();
    };
    
    //...
    
    var controlEventoKeyUp = function (event) {
    
        var _plugin = this['plugin_' + pluginName];
    
        if (_plugin.options.maxLen < $(this).val().length) {
            $(this).val($(this).val().substr(0, _plugin.options.maxLen));
        }
        else {
            _plugin.asignarValorActual();
        }
    
        if (_plugin.options.textUppercase) { 
            $(this).val($(this).val().toUpperCase());
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this structure (from markItUp plugin): It's image button with CSS a:hover element.
Not sure if I'm approaching this correctly ... Basically I have a plugin structure
I have this plugin advImage which I use in tinyMce. I want the user
Anyone have experience with this plugin? I have it installed but I have no
I have a plugin that is loaded by this application.. This plugin calls some
I have this code somewhere in my plugin: $('tr', $this).hover(function(){ var cur_color = null;
I install plugin open_id_authentication and have this error: /usr/lib/ruby/gems/1.9.1/gems/activesupport-3.0.0.beta/lib/active_support/dependencies.rb:167:in `require': no such file to
Again I have a question regarding this plugin: http://t.wits.sg/2008/06/20/jquery-progress-bar-11/ What I want to achieve
I'm using this jquery plugin ajaxFileupload in our project. My design is I have
how do i solve this: I have usercredential informtion in my main RCP plugin.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.