Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set the counter into an element by ID #111

Open
Necrospasm opened this issue Dec 4, 2015 · 1 comment
Open

Set the counter into an element by ID #111

Necrospasm opened this issue Dec 4, 2015 · 1 comment

Comments

@Necrospasm
Copy link

Hi,

Any idea how I can put the counter in an existing element? I basically have (as per screenshot) an area where to show a counter which I want to use instead of having the counter floating around.

Any help appreciated.
Thanks.

textmessage

@nate99pitt
Copy link

nate99pitt commented Aug 12, 2016

Necrospasm, per the API docs .... the value for the placement property can be set as one of three things.

It can be a string, such as
placement: "top left"

It can be an object, such as
placement: {'top':'10px', 'left':30px'}

Or it can be a callback function such as

placement: function(a, b, c){
       // a is the element that it is binded to, in other words the object whose length you are checking
       // b is the element that is being created, in other words the character counter output
       // c contains info useful for positioning the counter, such as the offsets of the object. the width
       of the object, etc.
  }

Here is an example of how I used the function .....

 $('input[maxlength]').maxlength({
                     alwaysShow:true, 
                     showOnReady:true, 
                     appendToParent:true, 
                     warningClass:'', 
                     placement:function($cont, $obj, pos){             
                            $cont.parent().next().html($obj); 
                     }
}); 

... I have a bootstrap horizontal form. The grid is divided as follows ... label is set to "col-sm-2" the input is wrapped in a div with "col-sm-9" and the last grid is set to "col-sm-1". With the function above, for each of my inputs that have a max length defined, the object is appended to the sibling container (the last grid item).

The author did a really good job of providing hooks to make this utility very flexible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants